Tip : This is my personal IT resource website, you can go in and have a look
Now that docker is used more and more, let’s sort out the process of installing mysql with docker today. Generally, we use docker to install applications. It is best to mount some important files of the application to the host, so that we can compare it when viewing Convenient, no need to enter the container to view. If all the files are in the container, once the container is deleted, all the files will not exist. So today, when we install mysql with docker, we will use the mysql configuration file my.cnf and the mysql data. And logs are mounted on the host.
table of Contents
Download the mysql5.7 image
docker pull mysql:5.7
Use the command to view the mirror
docker images
Create three folders on the host
mkdir -p /data/mysql/conf && mkdir -p /data/mysql/data && mkdir -p /data/mysql/log
Enter the conf directory to create the my.cnf file
[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
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
Create a mysql container and mount the directory
docker run --name mysql -p 3306:3306 -v /data/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /data/mysql/data:/var/lib/mysql -v /data/mysql/log:/var/log/mysql -e MYSQL_ROOT_PASSWORD=root --restart=always -d mysql:5.7
Check if the container is created successfully
docker ps
Use NAVICAT remote connection
end
So far, using docker to create a mysql container is successful!