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
123WORDPRESS.COM--HTML超文本标记语言速查手册<!-- --> !D...
There are many database management tools for MySQ...
Preface This article will share some docker-compo...
The <input> tag The <input> tag is us...
Since the entire application needs to be deployed...
Virtualization 1. Environment Centos7.3 Disable s...
background I have a project service that uses AWS...
The SQL JOIN clause is used to join rows from two...
Table of contents Preface 1. Use global unified o...
1. Enable remote access to the docker server Log ...
In the /etc/my.conf file, add the following line ...
Table of contents Introduction to the Decorator P...
Table of contents Preface text 1. Panel 2. Huaron...
1. Create a folder to store nginx shell scripts /...
What is content overflow? In fact, when there is ...