Docker installs the image and runs it as a container

1.Docker role

In a project, the deployment needs to depend on node.js, Redis, RabbitMQ, MySQL, etc. The function libraries and dependencies required for the deployment of these services are different, and there may even be conflicts. It brings great difficulties to deployment.

And Docker has solved these problems ingeniously,

In order to solve the dependency compatibility problem, Docker adopts two methods:

  • Package the application's Libs (function library), Deps (dependency), configuration and application together

  • Run each application in an isolated container to avoid mutual interference

2. Common operating commands and concepts

Image : Docker packages applications and their required dependencies, function libraries, environments, configurations, and other files together, called images. (Usually a compressed package ending in .tar or .zip)

Container : The process formed after the application in the image runs is a container , but Docker will isolate the container process, which is invisible to the outside world.

A mirror image is a file package formed by packaging an application file on the hard disk, its operating environment, and some system function library files together. This package is read-only.

The container is to load the programs and functions written in these files into the memory to allow them to form a process, but they need to be isolated. Therefore, an image can be started multiple times to form multiple container processes.

After downloading a QQ, if we package the running files of QQ on the disk and the dependencies of the operating system it runs on, a QQ image is formed. Then you can start multiple times, double open, or even open QQ three times, and chat with multiple girls.

The image runs like a container, and one image can run multiple containers

DockerHub

https://hub.docker.com/

Is the address of the official download mirror.

1. Download mirror

1) First go to the mirror warehouse to search for nginx images, such as DockerHub :

2) According to the viewed image name, pull the image you need, and use the command: docker pull nginx

3) Use the command: docker images to view the pulled image

2. Save and import the image 

 

Use docker save to export the nginx image to the disk, and then load it back through load

1) Use the docker xx --help command to view the syntax of docker save

For example, to view the save command usage, you can enter the command:

docker save --help

2) Use docker save to export the image to disk

Run the command:

docker save -o nginx.tar nginx:latest

The result is shown in the figure:

3) Use docker load to load the image

First delete the local nginx mirror:

docker rmi nginx:latest

Then run the command to load the local file:

docker load -i nginx.tar

result:

 

 2. Container Operations

The command to create and run the nginx container:

docker run --name containerName -p 80:80 -d nginx

Command interpretation:

  • docker run : create and run a container

  • --name : Give the container a name, such as mn

  • -p : Map the host port to the container port, the left side of the colon is the host port, and the right side is the container port

  • -d: run the container in the background

  • nginx: mirror name, such as nginx

The parameter here -pis to map the container port to the host port.

By default, the container is an isolated environment. If we directly access port 80 of the host, we will definitely not be able to access nginx in the container.

Now, associate 80 of the container with 80 of the host. When we access port 80 of the host, it will be mapped to 80 of the container, so that we can access nginx:

 

Guess you like

Origin blog.csdn.net/sharesb/article/details/128329324