Docker study notes [two]

Before Docker runs the container, the corresponding image needs to exist locally. If the image does not exist locally, Docker will download the image from the image repository.

1. Get the image, which is obtained from Docker Hub by default .

Command docker pull 

2. Run the container, if you plan to start the bash inside and perform interactive operations, execute the following command docker run

Exit this container with exit

3. List mirrors

docker image ls

4. Mirror volume

Use docker system df to view the space occupied by images, containers, and data volumes.

5. Delete the local mirror

docker image rm command

Take a look at all containers docker ps -as

I saw an article on stackoverflow that mentioned that you need to delete the container first to be able to delete the image.

6. Use commit to understand the mirror composition

Let's customize a web server as an example. This command will start a container with nginx image, name it webserver, map it to port 80, and access it through a browser.

Modify the content of the home page.

We modified the file of the container, that is, changed the storage layer of the container. It can be viewed with the docker diff command.

Now hopefully it can be saved as a mirror image. Use the docker commit command.

 

New customized image, we can run this image.

docker run --name web2 -d -p 81:80 nginx:v2

The concept of hierarchical storage can be intuitively understood through the docker commit command, but it is not used in the actual environment.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324405900&siteId=291194637