What is a Docker?

Docker provides us with an isolated and secure running software environment (container). Compared to virtual machines, Docker is more lightweight, takes up fewer resources, and can run more containers on a given combination of hardware. To put it simply, Docker can simulate multiple independent operating environments on a host just like a virtual machine, just like multiple hosts, and save more resources than virtual machines.

Docker installation

Docker supports Mac, Windows, and Linux.

The Mac platform is available from www.docker.com/get-started… Cask install docker `.

After installing the Docker, domestic image of accelerator best configuration, otherwise, the mirror download a lot, to accelerate the address suggested configuration for the image of China university of science and technology, the accelerator (docker.mirrors.ustc.edu.cn)

On a Mac, perform the following steps:

Click the docker small icon in the upper navigation bar of the system -> Preferences -> Docker Engine, configure the acceleration address, click the Apple&Restart button in the lower right corner to restart.

After the restart, run the Docker Info command on the console. If the following information is displayed at the end of the information, the configuration is successful

Docker container

Previously, we said that Docker can provide an isolated container to run software. In Docker, our software needs to be packaged into an image to run in the container. In other words, if we want to run our own software inside the Docker container, we need to package our software into the image first. Don’t rush to run our own software, docker image library already has a lot of other people’s images, let’s run an image of others to try first. Of course, you can search hub.docker.com to see which images are available, or you can directly use the command to search, for example, we look at the centos image, that can be console run docker search centos.

Of course, what versions do you have available inhub.docker.comLook inside.

Centos7 version is available, so we can pull the image of Centos7 to our local, execute the Docker pull centos: Centos7 and wait slowly, after downloading, we can check the image of the local through Docker images. You can see that the centos image has been pulled locally.

Now we can run centos in the container: Docker run – I – t centos: centos7 / bin/bash, among them – I said standard input and output, -t said open a terminal, run/bin/bash, namely centos terminals, as the chart, We have entered the terminal terminal of centos running in the container.

control+q+pKey to go back to our system.docker psCommand to see the Docker container we are currently running, you can see that we already have a container running.

Example docker stop c2CC74725D20. At this time, we can not see the container after executing docker PS. We can use docker ps -a to view all containers including stop.

Docker start c2CC74725d20

Docker exec container ID /bin/bash Docker exec it c2cc74725d20 /bin/bash

Docker command can be viewed by docker –help. Specific parameters such as run can be used. What parameters can be viewed by docker run –help

docker search centos docker pull centos:centos7 docker images docker run -i -t centos:centos7 /bin/bash docker ps docker Ps -a docker stop container ID docker start container ID docker exec it c2CC74725d20 /bin/bash docker --help docker run --helpCopy the code

conclusion

So far, this article briefly describes what Docker is, Docker installation, using Docker to run our first container. More on Docker, such as how to package our code into an image, later.