查看mysql镜像
从下面网址可以查看关于mysql的镜像
https://container-registry.oracle.com/
创建容器mysql5.7
从oracle容器仓库中拉取mysql 5.7社区版本
[root]# docker pull container-registry.oracle.com/mysql/community-server:5.7
查看镜像信息
[root]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
container-registry.oracle.com/mysql/community-server 5.7 55db19768c9c 2 years ago 375MB
宿主机创建相关目录
[root]# mkdir -p /data/docker_mysql5.7_01/{data,etc}
配置my.cnf文件
[root]# vi /data/docker_mysql5.7_01/etc/my.cnf
[mysqld]
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
创建mysql5.7_01容器
[root]# docker run --name=mysql5.7_01 --mount type=bind,src=/data/docker_mysql5.7_01/data,dst=/var/lib/mysql --mount type=bind,src=/data/docker_mysql5.7_01/etc/my.cnf,dst=/etc/my.cnf -p 3301:3306 --env MYSQL_ROOT_PASSWORD=Your_passwd -d 55db19768c9c
创建容器mysql8.0
从oracle容器仓库中拉取mysql 8.0社区版本
[root]# docker pull container-registry.oracle.com/mysql/community-server:8.0
查看镜像信息
[root]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
container-registry.oracle.com/mysql/community-server latest ed3919bfd3bd 4 weeks ago 546MB
宿主机创建相关目录
[root]# mkdir -p /data/docker_mysql8.0_01/{data,etc}
配置my.cnf文件
[root]# vi /data/docker_mysql8.0_01/etc/my.cnf
[mysqld]
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
创建mysql8.0_01容器
[root]# docker run --name=mysql8.0_01 --mount type=bind,src=/data/docker_mysql8.0_01/data,dst=/var/lib/mysql --mount type=bind,src=/data/docker_mysql8.0_01/etc/my.cnf,dst=/etc/my.cnf -p 3302:3306 --env MYSQL_ROOT_PASSWORD=Your_passwd -d ed3919bfd3bd
升级容器mysql5.7到mysql8.0
拉取mysql8.0社区版镜像
[root]# docker pull container-registry.oracle.com/mysql/community-server:8.0
查看镜像信息
[root]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
container-registry.oracle.com/mysql/community-server latest ed3919bfd3bd 4 weeks ago 546MB
从mysql 5.7升级到8.0
[root]# docker run --name=mysql8.0_02 --mount type=bind,src=/data/docker_mysql5.7_01/data,dst=/var/lib/mysql --mount type=bind,src=/data/docker_mysql5.7_01/etc/my.cnf,dst=/etc/my.cnf -p 3303:3306 --env MYSQL_ROOT_PASSWORD=Your_passwd -d ed3919bfd3bd
参考:https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html