Docker creates Mysql container

1. Start docker service

[root@docker ~]# systemctl start docker

2. View the image in docker

[root@docker ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
centos/mysql-57-centos7   latest              2e4ddfafaa6f        6 months ago        445MB
gogs/gogs                 latest              2fb3b88053d6        6 months ago        94.2MB

3. Search the image name you want to query

[root@docker ~]# docker search mysql

NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                                                  MySQL is a widely used, open-source relation...   7854                [OK]                
mariadb                                                MariaDB is a community-developed fork of MyS...   2604                [OK]                
cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0     

[root@localhost ~]# docker pull mysql ------------- download the latest version by default
[root@localhost ~]# docker pull mysql:5.7 -------- download the specified version                            

4. Create and run a mysql container

[root@docker ~]# docker run -di --name=test_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root  centos/mysql-57-centos7 
d7e5f99b502a904a970026e90227e186107e3b5d0baeaa93491af12cd7317b99

Run: create and run
 -di: created in guardian mode
 --Name: give the container a name
 -p: port mapping
 -e: initialize Mysql user and set root password to root
 The last one is the name of the image. If you do not specify the version, the latest one will be created by default

5. View the running container

[root@docker ~]# docker ps
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                    NAMES
d7e5f99b502a        centos/mysql-57-centos7   "container-entrypoin..."   5 seconds ago       Up 4 seconds        0.0.0.0:3306->3306/tcp   test_mysql

6. You can connect the database in the virtual machine with the database tool on your own computer

IP is the IP to connect the virtual machine, account: root, password: root

7. In fact, as long as you can pull one image, others are the same (such as redis,mogodb,rabbitmq, etc.)

Keywords: Docker MySQL CentOS MariaDB

Added by AceOfJames on Wed, 04 Dec 2019 22:48:48 +0200