1.在mysql目录下,新建docker-compose-mysql.yml文件
[root@abc mysql]# pwd /home/middleware/mysql [root@abc mysql]# cat docker-compose-mysql.yml version: '2.0' services: mysql: image: mysql:latest container_name: mysql8.0 restart: always command: --default-authentication-plugin=mysql_native_password ports: - 3306:3306 volumes: - /etc/localtime:/etc/localtime:ro - /home/middleware/mysql/data:/var/lib/mysql - /home/middleware/mysql/logs:/var/log/mysql - /home/middleware/mysql/conf:/etc/mysql - /home/middleware/mysql/init:/docker-entrypoint-initdb.d network_mode: "bridge" environment: MYSQL_ROOT_PASSWORD: 123456 MYSQL_USER: lee MYSQL_PASS: 1234562.根据定义的yml文件新建conf文件夹,并在文件夹下新建my.cnf的文件,文件内容如下
[root@abc conf]# pwd /home/middleware/mysql/conf [root@abc conf]# ls my.cnf [root@iZwz93g1c5ttsmy1iwxnveZ conf]# cat my.cnf [mysqld] user=mysql character-set-server=utf8 default_authentication_plugin=mysql_native_password secure_file_priv=/var/lib/mysql expire_logs_days=7 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION max_connections=1000 secure_file_priv=/var/lib/mysql [client] default-character-set=utf8 [mysql] default-character-set=utf83.启动mysql,并查看是否启动。
[root@abc mysql]# docker-compose -f docker-compose-mysql.yml up -d [root@abc mysql]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bbcc53579b70 mysql:latest "docker-entrypoint.s…" 31 minutes ago Up 9 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql8.0 2fccecdd4502 jenkins/jenkins:lts "/sbin/tini -- /usr/…" About an hour ago Up About an hour 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins 33494b7bb2c9 redis:latest "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:6379->6379/tcp redis4.0