This article briefly describes how to use Docker to deploy MySQL and persist data. We will use the tutum-docker-mysql project to build a MySQL server, saving the time of rewriting the Dockerfile. First we run tutum-docker-mysql. docker run -d -p 3306:3306 --name mysql tutum/mysql If you don't have the tutum/mysql image locally, Docker will download its image first. This step may take some time. After the execution is completed, we check that it should look like this tutum-docker-mysql will automatically create a random password for us to access, which can be viewed through the log. We log in to mysql through the password in the log mysql -uadmin -pi6k5USp9Km9G -h127.0.0.1 Theoretically, we have successfully logged into MySQL at this point. You can create a database, a table, and then exit. But when the container is stopped and restarted, your data will be lost. How can you really save your data? The solution is to mount a local file to the Container (Mount a local folder from the host on the container to store the database files). First, we stop the previous Container docker stop mysql We specify a local mountable path and restart tutum-docker-mysql. We specify /home/walter/softwares/tutum-docker-mysql/data to be mounted to the /var/lib/mysql directory in the Container (-v Bind mount a volume). In this way, we can persist the data in the directory of the host. sudo docker run -d -p 3306:3306 -v /home/walter/softwares/tutum-docker-mysql/data:/var/lib/mysql -e MYSQL_PASS="mypass" tutum/mysql When we started it above, we specified the password to create it as mypass. Now let's log in to MySQL and create some data to see if it will be saved. shell>mysql -uadmin -pmypass -h127.0.0.1 mysql>create database test; Exit mysql and restart the Container. The operations we have performed will be retained. Each time we start mysql, we can use the following command docker run -d -p 127.0.0.1:3306:3306 -v /home/walter/softwares/tutum-docker-mysql/data:/var/lib/mysql tutum/mysql The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Nodejs implements intranet penetration service
>>: MySQL 8.0.12 decompression version installation graphic tutorial under Windows 10
This article shares the specific code of JavaScri...
Table of contents 01 Create invisible columns 02 ...
1 Requirements Overview The data of multiple tabl...
Previously, I summarized how to use CSS to achieve...
It has been a long time since the birth of vue3, ...
Recently, I found that the company's server t...
Table of contents 1. What is Dockerfile? 2. Analy...
background Temporary tablespaces are used to mana...
rm Command The rm command is a command that most ...
Effect diagram: Overall effect: Video loading: Ph...
Notice! ! ! select * from user where uid not in (...
BMP is an image file format that is independent o...
CentOS6.9+Mysql5.7.18 source code installation, t...
This article example shares the specific code of ...
Crontab is a command used to set up periodic exec...