Kubernetes certification exam self-study series | Practical exercises - create mysql container

Book source: "CKA/CKAD Test Guide: From Docker to Kubernetes Complete Raiders"

Organize the reading notes while studying, and share them with everyone. If the copyright is violated, it will be deleted. Thank you for your support!

Attach a summary post: Kubernetes certification exam self-study series | Summary_COCOgsta's Blog-CSDN Blog


When using mysql mirroring, you need to specify at least one variable MYSQL_ROOT_PASSWORD to specify the root password. Other variables, such as MYSQL_USER, MYSQL_PASSWORD, and MYSQL_DATABASE are optional.

[root@vms100 ~]# docker history hub.c.163.com/library/mysql
IMAGE           CREATED        CREATED BY                          SIZE  COMMENT 
9e64176cd8a2    2 years ago    /bin/sh -c #(nop) CMD["mysqld"]     0 B  
...
[root@vms100 ~]#
复制代码

You can see that mysqld is running in the container created using the mysql image.

Step 1: Create a container.

[root@vms100 ~]# docker run -d --name=db --restart=always -e MYSQL_ROOT_PASSWORD=redhat -e MYSQL_DATABASE=blog hub.c.163.com/library/mysql 
debbb87bab89cc723807a3624189a357a6e38c492653482cc82f46032b9d6b18
[root@vms100 ~]#
复制代码

Here MYSQL_ROOT_PASSWORD is used to specify the MySQL root password as redhat, and a database is created in the container named blog (specified by the option -e MYSQL_DATABASE=blog).

Step 2: Do a connection test.

Use yum to install the mariadb client on the physical machine, the command is "yum -y install mariadb", and then connect to the container.

[root@vms100 ~]# mysql -uroot -predhat -h172.17.0.2
...
MySQL [(none)]> show databases;
+-------------------+
| Database          |
+-------------------+
| information_schema|
| blog              |
| mysql             |
| performance_schema|
| sys               |
+-------------------+
5 rows in set (0.00 sec)

MySQL [(none)]> exit 
Bye
[root@vms100 ~]#
复制代码

The IP of the container can be checked by the following command.

[root@vms100 ~]# docker exec db ip a | grep 'inet' #注意, inet后面有个空格
  inet 127.0.0.1/8 scope host lo 
  inet 172.17.0.2/16 scope global eth0
[root@vms100 ~]#

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/130180593