Docker usage experience and deploying a Mysql container


Recently, the company is using Docker. It is indeed a very useful thing. Like a container, it is stacked layer by layer. It is easy to operate, has strong practicability, and has very good performance. There are many ways to play, which can be combined with the actual situation of your own project. to customize.

 

Install Docker

 

The method can be seen on the official website, www.docker.com
is a seamless installation on Ubuntu 14.x and above:

$ which curl
$ sudo apt-get update
$ sudo apt-get install curl 
(如果有了curl忽略上面的3步)
$ curl -fsSL https://get.docker.com/ | sh
 

After completion, the docker installation is complete, and  sudo docker versionyou can check the current docker version number by hitting it.

 

 

The installation of Mac and Windows is a little troublesome, you need to install the official Docker Toolbox https://www.docker.com/products/docker-toolbox  is actually a virtual machine, and then run Ubuntu in the virtual machine to install Docker.

 

Download Mysql image

 

Mysql can be pulled from the official dockerhub, or you can use the acceleration service of aliyun. The speed is indeed much faster. Docker's own registry is assumed to be on AWS, and AWS's domestic access speed is simply unbearable.

docker pull mysql:5.5
 If there is no (tag) version number behind, the default is the latest version, which is the last version. After the download is complete, you can use the  docker images  command to see which images your current docker has downloaded.


 

start running this container

image : image, take this mysql image as an example, it can be understood as a virtual machine with mysql service installed, you can docker imagesview
container : container, after the image is started, it is a container, which can be stopped and started, but it will disappear after deletion , you can docker psview all currently running containers by



  

Because the container can't save the data, it can be lost when it is used, and it will be deleted after deletion, so it is not suitable to save the data in the container, so we run the mysql service in the container, and the data is stored in the host machine.

Note: The following solutions may not be suitable for implementation on Mac and Windows, at least not on Mac. I tried it,
but it cannot be implemented because the mysql user of the host machine and the mysql user in the container are inconsistent.

 

Create a folder on the host machine to store the data (data directory) of mysql, for example /home/tom/mysqldata, then run the image and start the container

docker run --name db -e MYSQL_ROOT_PASSWORD=root -d -v /home/tom/mysqldata:/var/lib/mysql/bluemountain mysql:5.6 --lower_case_table_name=1
 

Parameter explanation:

  • --name Specify the name of the container, here it is called db

  • -e Specify the root user password of mysql in the container

  • -v Directory mounting is to mount the data directory we created ourselves to the data directory of mysql in the container, so that the data is written to the host machine

  • --lower_case_table_name=1 Specify some configuration of mysql

 

After the startup is complete, hit the docker ps command, you can see all the containers currently running

 

 

use this container

 

So far, the container of mysql has been started, but how to use the container of other programs? In fact, it is very simple. When starting other containers, just bind this container.

dk run --name bm -d --link db:db bluemountain
 

--link db:db1It means that the currently running container can use  db1 this name to access db the named container

 

If there are mistakes, I hope to be corrected.

to do.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326860817&siteId=291194637