Docker installs mysql5.7 with mount start

1. Pull the mysql5.7 image

docker pull mysql:5.7

2. Verify whether the image is pulled successfully

docker images

3. Run the container

docker run -it --name 别名 -d -p 3306:3306 镜像ID

docker run -it --name mysql1 -d -p 3306:3306 2c9028880e58

4. Check whether the container is running successfully

docker ps

There is no container that runs successfully, because the mysql operation needs to specify the user name and password command

Delete containers that are not running successfully

Five, re-run mysql, specify the password as 123456

docker run -it --name mysql1 -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456  2c9028880e58

6. Check whether mysql runs successfully after specifying the password

docker ps

Shows that the container has run successfully

7. Configure mysql to mount and run

1. Create a new mysql directory under the home directory on the host, and copy conf.d, log , and mysql in the container to the host

docker cp  容器id:/etc/mysql/conf.d  /home/mysql/
docker cp  eb0630b28b07:/etc/mysql/conf.d  /home/mysql/
docker cp  容器id:/var/log  /home/mysql/
docker cp  eb0630b28b07:/var/log  /home/mysql/
docker cp  容器id:/var/lib/mysql  /home/mysql/ 
docker cp  eb0630b28b07:/var/lib/mysql  /home/mysql/

2. Stop the current container

docker stop eb0630b28b07

3. Mount the conf.d, log, and mysql in the mysql in the container to the mysql directory of the host machine , which is convenient for uploading code, synchronizing persistent logs, and conveniently configuring mysql

docker run --name 别名 -itd -p 3306:3306 -v /home/mysql/conf/:/etc/mysql/conf.d/ -v /home/mysql/log/:/var/log -v /home/mysql/mysql/:/var/lib/mysql/ -e MYSQL_ROOT_PASSWORD=123456  镜像ID

docker run --name mysql -itd -p 3306:3306 -v /home/mysql/conf/:/etc/mysql/conf.d/ -v /home/mysql/log/:/var/log -v /home/mysql/mysql/:/var/lib/mysql/ -e MYSQL_ROOT_PASSWORD=123456  2c9028880e58

Check if the container is running successfully

Those with obsessive-compulsive disorder can delete the previous mysql1.

view all containers

docker ps -a

tomcat1 is not running, let's delete it.

docker rm eb0630b28b07

​​​​​​​

ok, mysql1 has been deleted, leaving a mysql container.

The container aliased as: mysql has run successfully.

8. Verify whether mysql can be used

1. Open the mysql graphical tool, I use sqlyog here

2. My server host address is: 118.31.46.55 must be the server host address

3. The default user name is root, and the password is 123456 set by the command just now

4. The test connection is successful

Guess you like

Origin blog.csdn.net/qq_36539042/article/details/117596090