[Software Testing] Use Docker to build a CentOS environment on Windows (details)


foreword

When we do software testing, we will more or less come into contact with Linux servers in our daily work.

There are also many ways to obtain Linux servers, such as purchasing cloud servers (Aliyun, Huawei Cloud, Tencent Cloud, etc.) and virtual machines (VMWare, VirtualBox, etc.). In addition to these two methods, we can also use Docker way to quickly build a Linux environment.

Compared with the method of virtual machine, the advantages of using Docker to build CentOS are mainly reflected in the following aspects:

Resource utilization: Docker containers are more lightweight than virtual machines, start faster, and take up fewer resources on the physical host. Compared with virtual machines, Docker containers can use system resources more efficiently, making it possible to run more container instances on the same host.

Deployment speed: Docker containers can be quickly deployed and started from images. Starting a Docker container can be done in almost seconds compared to a virtual machine, which takes a long time to start. This is very beneficial for rapid deployment and elastic scaling, especially in the face of high traffic and changing demand scenarios.

System overhead: Docker containers share the host's kernel, reducing additional system overhead. In contrast, virtual machines need to emulate the entire operating system, and each virtual machine requires independent kernel and operating system resources, which results in higher system overhead and performance loss.

Easy management and operation: Docker provides a wealth of command-line tools and APIs, making container management and operation easier. Use Docker to quickly build, modify, start and stop containers, and manage the network, storage, and configuration of containers. In contrast, hypervisor software is often complex and requires specialized operation and configuration.

1. Create and start a container
Use the docker run command to install and run a CentOS instance:

docker run -itd -p 50022:22 --name my_centos7 --privileged=true centos:centos7 /usr/sbin/init

Please add a picture description

Parameter explanation:

OPTIONS effect
-i Run the container in interactive mode, usually with -t
-t Reassign a pseudo-input terminal to the container, usually used with -i
-d Run the container in the background and return the container ID
50022:22 Map port 22 of centos on docker to local port 50022, the port number can be specified by yourself
–name my_centos7 Specify a name for the container, here the container name is my_centos7, you can specify it yourself
–privileged=true To enable permissions, to connect to Xshell, you need to create a container with access privileges and mapped ports
hundreds: hundred7 The centos in front indicates the name of the software source, followed by the version label (query the version on dockerhub)

Please add a picture description

2. Enter the running container
Use the docker exec command to enter the CentOS container:

docker exec -it my_centos7 /bin/bash
OPTIONS effect
-i keep STDIN open even when not attached
-t allocate a pseudo-terminal
my_centos7 container name

3. Install the common toolkit
net-tools:
Install the net-tools toolkit (you can use the ifconfig command after installation):

yum install net-tools

Please add a picture description

Please add a picture description

passwd:

Install the passwd tool, and you can modify the user password after installation (CentOS has no password by default after installation, in order to use tools such as Xshell to connect to CentOS, set a password for the root user here):

yum install passwd
passwd root

Please add a picture description

4. Xshell connects to CentOS
to install ssh service:

yum install openssh-server

Please add a picture description

Start the ssh service:

systemctl start sshd.service

Set the ssh service to start automatically at boot:

systemctl enable sshd.service

Enter ipconfig in the Windows command line window to view the Docker host ip:

Please add a picture description

Connect using Xshell

Please add a picture description

Please add a picture description

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)

Everyone has their own dreams and pursuits, but they can only be realized through constant struggle. Don't be afraid of failure, because setbacks are the only way to grow. Work hard, persist, never give up, and believe that the future will be even better!

Every minute and every second is precious, don't give up the life you want easily. No matter how bumpy the road ahead is, face it bravely and work hard, because only persistent efforts can bring you real gains and achievements.

Only by constantly working hard and struggling can we make ourselves stronger and achieve higher goals. Every attempt is an improvement, even if the road ahead is long, we must keep moving forward and move forward bravely. Believe in yourself, you can definitely become who you want to be!

Guess you like

Origin blog.csdn.net/m0_70102063/article/details/131272142