본문 바로가기
linux/docker

centos7 docker mysql8.0.35 적용기

by 후린트 2024. 1. 29.
반응형

현재 mysql 5.7 버전이 동작하고 있는 서버에 mysql 8.0.35 버전을 docker로 
구동시키기 위해서 삽질한걸 기록한다.

서버 정보 

$ docker version
Client:
 Version:           18.09.6
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        481bc77156
 Built:             Sat May  4 02:34:58 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       481bc77
  Built:            Sat May  4 02:02:43 2019
  OS/Arch:          linux/amd64
  Experimental:     false

OS version
$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

 

기존 3306포트는 mysql 5.7 버전에서 사용하고 있으므로 포트를 17036으로 변경 처리 

mysql8.yml

version : '2'

services:
  test_mysqldb8:
    #image: centos/mysql-57-centos7:5.7
    image: mysql:8.0.36-oracle
    container_name: 'test-compose-mysql8.0.35'
    ports:
      - 17306:3306
    # docker를 구동하는 계정의 uid
    user: "1001"
    environment:
      - MYSQL_ROOT_PASSWORD=test123$$
      - MYSQL_USER=karint
      - MYSQL_PASSWORD=karint
      - MYSQL_DATABASE=karint
      - TZ= Asia/Seoul
    # - DATABASE_ALREADY_EXISTS='false'
    volumes:
      - /mysql/8.0/data:/var/lib/mysql
    #  - /mysql/8.0/initdb/:/docker-entrypoint-initdb.d/
    #network_mode : host
    #restart: always

실행 :
$sudo mkdir -p /mysql/8.0
$sudo chown -R hulint:hulint /mysql
$ docker-compose -f ./mysql8.yml down &&  docker-compose -f ./mysql8.yml up

결과 : 실패 

Removing test-compose-mysql8.0.35 ... done
Removing network test_default
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Creating network "test_default" with the default driver
Creating test-compose-mysql8.0.35 ... done
Attaching to test-compose-mysql8.0.35
test-compose-mysql8.0.35 | 2024-01-29 08:17:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
test-compose-mysql8.0.35 | 2024-01-29 08:17:03+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
test-compose-mysql8.0.35 | 2024-01-29 08:17:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
test-compose-mysql8.0.35 | ls: cannot access '/docker-entrypoint-initdb.d/': Operation not permitted
test-compose-mysql8.0.35 exited with code 2

 

도커가 구동될때 /docker-entrypoint-initdb.d/ 경로에 있는 스크립트 및 sql파일을 실행하는데 
별도의 스크립트 실행없이 구동시키기 위해서  아래 환경 변수 추가
- DATABASE_ALREADY_EXISTS='false' 

 

다시 실행 
$ docker-compose -f ./mysql8.yml down &&  docker-compose -f ./mysql8.yml up

실패 

Removing test-compose-mysql8.0.35 ... done
Removing network test_default
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Creating network "test_default" with the default driver
Creating test-compose-mysql8.0.35 ... done
Attaching to test-compose-mysql8.0.35
test-compose-mysql8.0.35 | 2024-01-29 08:56:15+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
test-compose-mysql8.0.35 | 2024-01-29 08:56:16+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
test-compose-mysql8.0.35 | 2024-01-29 08:56:16+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
test-compose-mysql8.0.35 | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
test-compose-mysql8.0.35 | 2024-01-29T08:56:16.669906Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
test-compose-mysql8.0.35 | 2024-01-29T08:56:16.672251Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.36) starting as process 1
test-compose-mysql8.0.35 | 2024-01-29T08:56:16.682753Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
test-compose-mysql8.0.35 | 2024-01-29T08:56:16.683110Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
test-compose-mysql8.0.35 | 2024-01-29T08:56:16.683168Z 0 [ERROR] [MY-010119] [Server] Aborting
test-compose-mysql8.0.35 | 2024-01-29T08:56:16.683944Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.36)  MySQL Community Server - GPL.
test-compose-mysql8.0.35 exited with code 1

 

OS버전이 낮아서 그런건지 docker버전이 낮아서 그런건지 에러가 발생하면서 구동되지 않는다.

검색을 통해서 이런저런 방법을 찾아봤지만 안되서 5.7버전을 설치한뒤 8.0버전으로 업데이트를 해서
8.0버전으로 구동했다는 글을 확인하고 해당 내용으로 적용 
https://github.com/docker-library/mysql/issues/69#issuecomment-590700916


기존 mysql8.yml파일에서 image와 volumn 부분 수정
- 이미지를 centos mysql 5.7 버전 적용
- volume을 5.7 버전에 맞게 수정 

services:
  test_mysqldb8:
    image: centos/mysql-57-centos7:5.7
    #image: mysql:8.0.36-oracle
    user: "1001"
...
...
   volumes:
     - /mysql/8.0/data:/var/lib/mysql/data
     #- /mysql/8.0/data:/var/lib/mysql
      
...

# DB data 디렉토리 권한 추가 
- sudo mkdir -p /mysql/8.0/data && sudo chown -R hulint:hulint /mysql/8.0/data

실행 
$ docker-compose -f ./mysql8.yml down &&  docker-compose -f ./mysql8.yml up

test-compose-mysql8.0.35 | 2024-01-29T10:04:42.051593Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/data/ib_buffer_pool
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.052045Z 0 [Note] Plugin 'FEDERATED' is disabled.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.054669Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240129 10:04:42
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.060446Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.060475Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.061407Z 0 [Warning] CA certificate ca.pem is self signed.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.061492Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.062158Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.062231Z 0 [Note] IPv6 is available.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.062246Z 0 [Note]   - '::' resolves to '::';
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.062274Z 0 [Note] Server socket created on IP: '::'.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.065863Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.065918Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.065940Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.065982Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.066000Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.066036Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.067635Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.067666Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.077991Z 0 [Note] Event Scheduler: Loaded 0 events
test-compose-mysql8.0.35 | 2024-01-29T10:04:42.078411Z 0 [Note] /opt/rh/rh-mysql57/root/usr/libexec/mysqld: ready for connections.
test-compose-mysql8.0.35 | Version: '5.7.24'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

정상 구동 확인 
ctrl+c로  종료후 yml파일을 8.0.35 버전으로 변경하여 다시 구동

기존 yml파일에서 image와 volumn 부분 수정
- 이미지를 centos mysql 8.0.36 버전 적용
- volume을 8.0.36 버전에 맞게 수정 

services:
  test_mysqldb8:
    #mage: centos/mysql-57-centos7:5.7
    image: mysql:8.0.36-oracle
    user: "1001"
...
...
   volumes:
     #- /mysql/8.0/data:/var/lib/mysql/data
     - /mysql/8.0/data:/var/lib/mysql 
...


다시 실행 
$ docker-compose -f ./mysql8.yml down &&  docker-compose -f ./mysql8.yml up

WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Creating network "test_default" with the default driver
Creating test-compose-mysql8.0.35 ... done
Attaching to test-compose-mysql8.0.35
test-compose-mysql8.0.35 | 2024-01-29 10:09:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.36-1.el8 started.
test-compose-mysql8.0.35 | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
test-compose-mysql8.0.35 | 2024-01-29T10:09:04.087732Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
test-compose-mysql8.0.35 | 2024-01-29T10:09:04.090202Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.36) starting as process 1
test-compose-mysql8.0.35 | 2024-01-29T10:09:04.093913Z 0 [Warning] [MY-010122] [Server] One can only use the --user switch if running as root
test-compose-mysql8.0.35 | 2024-01-29T10:09:04.102090Z 1 [System] [MY-011012] [Server] Starting upgrade of data directory.
test-compose-mysql8.0.35 | 2024-01-29T10:09:04.102168Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
test-compose-mysql8.0.35 | 2024-01-29T10:09:04.846358Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
test-compose-mysql8.0.35 | 2024-01-29T10:09:05.990313Z 2 [System] [MY-011003] [Server] Finished populating Data Dictionary tables with data.
test-compose-mysql8.0.35 | 2024-01-29T10:09:06.789101Z 5 [System] [MY-013381] [Server] Server upgrade from '50700' to '80036' started.
test-compose-mysql8.0.35 | 2024-01-29T10:09:11.692149Z 5 [System] [MY-013381] [Server] Server upgrade from '50700' to '80036' completed.
test-compose-mysql8.0.35 | 2024-01-29T10:09:11.782656Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
test-compose-mysql8.0.35 | 2024-01-29T10:09:11.782715Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
test-compose-mysql8.0.35 | 2024-01-29T10:09:11.785702Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
test-compose-mysql8.0.35 | 2024-01-29T10:09:11.812293Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
test-compose-mysql8.0.35 | 2024-01-29T10:09:11.812260Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock

 

정상적으로 구동 되는 것을 확인
서비스로 구동을 위해서 데몬 옵션을 추가하여 다시 실행

$ docker-compose -f ./mysql8.yml down &&  docker-compose -f ./mysql8.yml up -d

 

os버전과 docker버전이 오래되서 발생한 문제인지 아니면 mysql 이미지에 문제가 있는건지 모르겠지만
5.7버전으로 docker-compose로 구동하고 종료한뒤 8.0.35버전으로 구동을 하게 되면 5.7-> 8.0 버전으로
자동 업그레이드 되면서 서버가 구동됨

정상적인 방법은 아니고 편법으로 해결함

반응형

'linux > docker' 카테고리의 다른 글

일반 계정으로 docker 실행하기  (1) 2024.01.31
docker-compose network 설정  (0) 2020.09.22
docker pull proxy 설정  (0) 2020.09.18
docker tar로 만들기, tar import 하기  (0) 2020.09.16
Docker arg와 env사용 방법  (0) 2020.09.16