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]
Download the image to local
[root@wls12c ~]$ docker pull mysql
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
-e, specify environmentVariables .
Get the IP of the mysql mirror
[root@wls12c ~]$ docker inspect mysqldb|grep IPAddress "IPAddress": "172.17.0.4", "SecondaryIPAddresses": null
Connect to mysql
[root@wls12c ~]$ mysql -h 172.17.0.4 -u root -p
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
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!