Many test partners, the most vexed is environmental problems. Especially for Windows testers, when it comes to configuring environment variables, that’s a lot of trouble. Every time I want to learn a new technology, I am always plagued by various environmental problems and cannot take the first step.

Is there a way around the configuration environment variable pit? Don’t tell me. There is. That is the Docker that this article will introduce to you. Learn it so you don’t need to configure environment variables anymore, and do it all in one place.

What can Docker do?

1. Set up the test environment to ensure the consistency of the test environment (why?) , to avoid environmental reasons caused by each other

2. Build all kinds of basic services, such as Chan Tao and Jenkins, which greatly reduce the cost of learning! (It’s nice not to have to study.)

3. Build test execution environment, such as the environment where we run automated tests

The difference between Docker and virtual machine

The biggest difference between Docker and virtual machine is that Docker shares the kernel of host machine, and each VIRTUAL machine has a separate kernel virtualized, as shown in the figure above.

Docker cannot be tested for backend compatibility because it does not have a separate virtual kernel. Anything operated on the system does not directly call the kernel, but needs to go through system call. Docker is used to install the image software of the operating system, which feels like running on the operating system. Therefore, even if Centos image is used, the kernel may also be Ubantu, as shown in the following figure:

Pros and cons of Docker

Advantages:

  • Lightweight: Because Docker does not need to virtualize the kernel, but directly shares the kernel of the host computer, so it saves a lot of resources. More software can be started with the same resources, and the startup speed is also faster

Disadvantages:

  • Advantage is disadvantage: Docker’s advantage is also its disadvantage, because all containers share a single kernel, and if one of them “breaks” the kernel, none of them will work properly

Three key technologies for Docker isolation

1. Each time the NameSpace starts a Docker process, it will allocate a network NameSpace for network isolation

2. Federated file systems can provide a separate view for each container, achieving isolation of file directories so that files in other containers cannot be accessed

3, Cgroups resource isolation, limit the current process to use the resource size, to achieve resource isolation

Docker installation

Here to the Mac system as an example, command and manual are relatively simple, online tutorials are also a lot of. May refer to: www.runoob.com/docker/maco…

May refer to other systems, there is a complete docker tutorial www.runoob.com/docker/dock… . Next, take Jenkins installation and startup as an example to give you a detailed demonstration

1. Download and install Jenkins image

Search Docker Hub, or directly visit hub.docker.com/, which is the official Docker image website, without logging in, directly enter the image to search in the search

More than 20,000 Jenkins images have been searched after the press enter. We need the Official image, and the one with the Official image is the Official image

Click to enter the image, there will be a lot of related documents, the right side of the installation command “docker pull Jenkins”, copy the command to the terminal to execute the automatic download and installation of Jenkins official image

Note: There is a pit here, where the default download is the latest Jenkins image, but the latest version is likely to be incompatible with many plug-in versions. If so, it is suggested to replace the version 2.164.3 which is more stable and compatible according to my actual test


Docker pull Jenkins/Jenkins: 2.164.3

You can use the Docker images command to view all images on your current machine

REPOSITORY represents the image name

TAG indicates the version of the image

IMAGE ID Indicates the IMAGE ID, which uniquely identifies the IMAGE

CREATED indicates the time at which the image was CREATED (note not our download time, but the time at which the current image was CREATED)

SIZE indicates the SIZE of the mirror

In order to prove that the IMAGE ID is the unique identifier of the IMAGE, we can use docker tag Jenkins myJenkins :5.5 command to add a new tag for the IMAGE Jenkins. After checking the IMAGE, we found an additional IMAGE named MyJenkins with tag 5.5. But when I look at the IMAGE ID, I see that it’s the same as the original, but it’s not changed

2.Docker general operations

Docker rmI {image name} can be used to delete the specified image; Note that a colon is used to specify the version of the mirror. If not, it defaults to latest

Docker ps-s-a docker ps-s-a docker ps-s-a docker ps-s-a

Run docker run -d –name= myJenkins Jenkins, name Jenkins myJenkins, and run the container in the background, we’ll get a run code

Docker rm -f myjenkins docker rm -f myJenkins docker rm -f myJenkins docker rm -f myJenkins

3. Start Jenkins service

Port mapping: Use docker run -d –name myjenkins -p 8080:8080 -p 505:50000 Jenkins to start the Jenkins service (host port: container port), The host machine will run in the background under the name myJenkins, and the host machine’s port 8080 request will be forwarded to the container’s port 8080.

After the command is executed we access the local port 8080:


It can be seen here that the Jenkins service has been successfully started. Since it is newly installed, Administrator password is required. This registration code will be generated when Jenkins is started. We can use docker logs -f myJenkins to get Jenkins startup run log and find the activation code:

4. Other common Docker commands

As a person:

Month pass, hogwarts Test Academy outstanding student. Tester, a climbing exploration in the field of quality assurance, is committed to using technology to change the way people around him understand testing. Web, interface and APP automation are involved

(Article from Hogwarts Testing Institute)

Welfare benefits:

Front-line Internet famous enterprises test development position internal promotion channel

Test development internal communication circle, expand your test network

For free: Interface testing + Performance testing + Automated testing + Test development + Test cases + resume template + test documentation