Home > Database > Mysql Tutorial > Use Docker to create a mysql container and save it as a local image

Use Docker to create a mysql container and save it as a local image

黄舟
Release: 2017-05-21 09:29:34
Original
1628 people have browsed it

This article mainly introduces Docker to create a mysql container and save it as a local image. The editor thinks it is quite good. Now I will share it with you and give it a reference. . Let’s follow the editor to take a look

Find the image on docker hub

[root@wls12c ~]$ docker search mysql
NAME           DESCRIPTION                   STARS   OFFICIAL  AUTOMATED
mysql          MySQL is a widely used, open-source relati...  2903   [OK]    
mysql/mysql-server    Optimized MySQL Server Docker images. Crea...  190         [OK]
centurylink/mysql    Image containing mysql. Optimized to be li...  46          [OK]
Copy after login

Download the image to local

[root@wls12c ~]$ docker pull mysql
Copy after login

The default download is the one officially maintained by docker, which is the first one searched.

Create container

Copy code The code is as follows:

[root@wls12c ~]$ docker run --name mysqldb -e MYSQL_ROOT_PASSWORD=root -d mysql
Copy after login

-e, specify environmentVariables .

Get the IP of the mysql mirror

[root@wls12c ~]$ docker inspect mysqldb|grep IPAddress
     "IPAddress": "172.17.0.4",
    "SecondaryIPAddresses": null
Copy after login

Connect to mysql

[root@wls12c ~]$ mysql -h 172.17.0.4 -u root -p
Copy after login

The password is the root specified above

Save the initialized mysql as a mirror

[root@wls12c ~]$ docker commit mysqldb mysql:1.0
3ed4a367c21eb509f1c4e0a772c3e5bdff678497be55700ea256ef34ad87cfc6
[root@wls12c ~]$ docker images
REPOSITORY     TAG         IMAGE ID      CREATED       VIRTUAL SIZE
mysql        1.0         3ed4a367c21e    3 seconds ago    384.6 MB
mysql        latest       826df4733292    37 hours ago    384.5 MB
centos       latest       d83a55af4e75    3 weeks ago     196.7 MB
cirros       latest       d8ca8144dee3    7 months ago    7.735 MB
Copy after login

The above is the detailed content of Use Docker to create a mysql container and save it as a local image. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template