SoFunction
Updated on 2025-03-09

Docker creates a mysql container and saves it as a local image

Find images 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 mirror to local

[root@wls12c ~]$ docker pull mysql

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

Create a container

Copy the codeThe code is as follows:

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

-e, specify environment variables.

 Get the IP of mysql image

[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 all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.