[Software testing] Docker build + Docker build MySQL service in Linux environment (details)


foreword

Linux docker build

1. The docker operating environment
is CentOS7 (64-bit), the system is required to be 64-bit, and the system kernel version is above 3.10

Check the system version:

cat /etc/centos-release

Check the system kernel version:

uname -a

2. docker installation
install dependency packages

yum install -y yum-utils device-mapper-persistent-data lvm2

Add docker download source address

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

update yum cache

yum makecache fast

install docker

yum install docker-ce

Or specify the installed version of docker

yum install docker-ce-17.12.1.ce

View docker version number

docker version

3. After the installation is successful, docker needs to be added to the startup item (docker is actually an application installed on the Linux system, and the service needs to be started first)

systemctl enble docker  #该命令不能用的话使用下面的命令试一下

systemctl enable docker.service

4. View version information

docker version

5. Start docker
to view the docker startup status: systemctl status docker
Start docker: systemctl start docker
Disable docker: systemctl stop docker

6. View the installed docker

yum list installed | grep docker

Delete the container image:

rm -rf /var/lib/docker

Uninstall docker (delete all installed dockers)

yum remove docker  docker-client   docker-client-latest  docker-common  docker-latest  docker-latest-logro

Docker builds MySQL service

1. Create a mirror
and download the official mirror

docker pull mysql:5.7   # 拉取 mysql 5.7
docker pull mysql       # 拉取最新版mysql镜像

Check if the pull is successful

docker images

Create a new mount directory

mkdir wxl2020
mkdir -p ~/wlx2020/mysql/conf ~/wlx2020/mysql/data

Start the container

docker run -p 3309:3306 --name mysql2020 -v  ~/wlx2020/mysql/conf:/etc/mysql/conf.d -v ~/wlx2020/mysql/logs:/logs -v  ~/wlx2020/mysql/data:/var/lib/mysql  -e
MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7  

Command description:
–name: container name, named mysql2020 here  
-p: 3309:3306 Here, port 3309 of the host is mapped to port 3306 of the container
-v: directory mapping relationship between the host and the container, ":" before the host directory, followed by the container directory (-v ~/wlx2020/mysql/conf:/etc/mysql/conf.d mounts the host's ~/wlx2020/mysql/conf to the container's /etc/mysql/conf.d)
- e: configuration information, here configure the login password of the root user of mysql
-d: source image name, here is mysql: 5.7 hanging background operation

If no mapping is required:

sudo docker run -p 3306:3306 --name mysql2020 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

Check that the container is running correctly

docker container ls

You can see the container ID, source image of the container, start command, creation time, status, port mapping information, container name

2. Connect to mysql
and enter the mysql2020 container to operate the mysql client

docker exec -it mysql2020 bash

Enter the mysql application and use the root user to operate mysql

mysql -uroot -p123456

Seeing mysql> indicates that it has entered mysql

After entering mysql, all commands must end with a ;semicolon

show databases: view all libraries
show tables: view table name
use: a certain database, such as use mysql;
select: query statement
quit: exit mysql
exit: exit the container

Use Navicat to connect to mysql
Open Navicat to connect to mysql and enter the configuration page

B1

Connection name: take any
host name or ip address: localhost is the local host, and the corresponding host address is on other machines
Port: 3309, the port set by the previous container
User name: root
Password: 123456, the password set by the previous container

Tips:
If the container is running normally, but cannot access mysql, there are several reasons for the general difficulty

firewall blocking

开放端口:
$ systemctl status firewalld
$ firewall-cmd  --zone=public --add-port=3309/tcp -permanent
$ firewall-cmd  --reload
# 关闭防火墙:
$ systemctl stop firewalld

You need to enter the docker local client to set up a remote access account

$ docker exec -it mysql bash
$ mysql -uroot -p123456
mysql> grant all privileges on *.* to root@'%' identified by "password"; 

principle

# mysql使用mysql数据库中的user表来管理权限,修改user表就可以修改权限(只有root账号可以修改)
 
mysql> use mysql;
Database changed
 
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host                    | user      | password                                                                 |
+--------------+------+-------------------------------------------+
| localhost              | root     | *A731AEBFB621E354CD41BAF207D884A609E81F5E      |
| 192.168.1.1            | root     | *A731AEBFB621E354CD41BAF207D884A609E81F5E      |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)
 
mysql> grant all privileges  on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host                    | user      | password                                                                 |
+--------------+------+-------------------------------------------+
| localhost              | root      | *A731AEBFB621E354CD41BAF207D884A609E81F5E     |
| 192.168.1.1            | root      | *A731AEBFB621E354CD41BAF207D884A609E81F5E     |
| %                       | root      | *A731AEBFB621E354CD41BAF207D884A609E81F5E     |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)  
The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Every effort lays the foundation for the future self. As long as we persist in pursuing our dreams, even if the journey is far away, we can overcome many difficulties and finally set sail to welcome our own glory.

No matter where you are at the moment, as long as you have a dream in your heart, move forward firmly, and work hard, you can surpass the ordinary and achieve extraordinary achievements. Believe in your own strength, let go of your ideals, burn your passion on the journey, and bloom the splendor of life.

Life is too short, time is too precious, don't be held back by fear, seize opportunities and move forward. No matter what difficulties you face, always maintain tenacity and passion, and work hard. Only in this way can you create your own brilliant life.

Guess you like

Origin blog.csdn.net/shuang_waiwai/article/details/132259577