Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic Command and Operation Logic of docker

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "the basic command and operation logic of docker". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Docker mirroring operation logic diagram:

Docker is a container, and there must be an image to run a container, because the image is the core of the container. When we run a service on docker, we need to run an image through docker run to enter the container. We can also use the docker commit command to make a container into an image, but note that you need to specify a complete image name (image name + version number) when making an image. Its default version number is latest, which is represented as a mirror of the latest version. If it is not written, it will end with latest by default.

You can also export the image by issuing the docker save-- output command, and when you need to download a service, you can use the docker load-- input command to import the image, or you can use the > sign or httpd.tar httpd:latest

/ / View the local image:

[root@sqm-docker01 ~] # docker images

Note: latest: indicates that it is a mirror of the latest version, but not absolutely up to date, because the TAG tag can be changed.

Full image name-> image:latest (image name + version number)

If the version number ends with latest by default, you can omit it.

/ / Delete the image:

[root@sqm-docker01 ~] # docker rmi httpd:latest

# add the-f option to force deletion:

[root@sqm-docker01] # docker rmi-f centos:latest

/ / Delete the container: (stop the container before deleting it)

[root@sqm-docker01 ~] # docker stop my_nginx my_ nginx [root @ sqm-docker01 ~] # docker rm my_nginx my_nginx

Also add the-f option to force deletion:

[root@sqm-docker01] # docker rm-f my_nginx my_nginx

/ / Import image:

[root@sqm-docker01 ~] # docker load < my-httpd.tar

Or use:

[root@sqm-docker01] # docker load-- input my-httpd.tar

/ / enter the container:

[root@sqm-docker01 ~] # docker exec-it test / bin/bash or [root@sqm-docker01 ~] # docker attach test

Note: if attach enters the container, the container will stop running after exiting, but exec will not

Exec entering the container will start a new process, but attach will not (enter the same terminal).

Ctrl + p ctrl + Q: if the container is entered by attach, ctrl + p ctrl + Q exits the container and keeps the container running. # notice that two shortcut keys have to be pressed at the same time

/ / Open the container:

[root@sqm-docker01 ~] # docker start test

/ / close the container:

[root@sqm-docker01 ~] # docker stop test

/ / restart the container:

[root@sqm-docker01 ~] # docker restart test

/ / Delete all containers:

[root@sqm-docker01 ~] # docker ps-a-Q | xargs docker rm-f

/ / Delete all images:

[root@sqm-docker01 ~] # docker images-Q | xargs docker rmi-f

/ / Open all containers:

[root@sqm-docker01 ~] # docker ps-a-Q | xargs docker start

/ / close all containers:

[root@sqm-docker01 ~] # docker ps-a-Q | xargs docker stop

/ / View the container log:

[root@sqm-docker01 ~] # docker logs test2

/ / update the log in real time:

[root@sqm-docker01] # docker logs test2-f

/ / keep the container open (for use after docker service restart)

[root@sqm-docker01] # docker run-itd-- name test3-- restart=always httpd

-- restart=always: restart with the restart of the container

/ / create an image of the container:

[root@sqm-docker01 ~] # docker commit web01 test-web:v1.0

The docker commit is followed by a container that needs to be made into an image, and the image name and label can be customized.

/ / run the container:

[root@sqm-docker01] # docker run-itd-- name my_nginx-p 80:80-- restart=always nginx:latest

Parameter explanation:

Run: run a container

-itd: I: interactive

T: pseudo terminal

D: keep the container running in the background

-- name: custom name is my_nginx

P: mapping port, host port: in-container port

-- restart=always: keep the container running

This is the end of the content of "basic commands and Operation Logic of docker". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report