Summary of common docker commands (recommended)

Summary of common docker commands (recommended)

1. Summary:

In general, they can be divided into the following categories:

Docker environment information — docker [info|version]
Container lifecycle management — docker [create|exec|run|start|stop|restart|kill|rm|pause|unpause]
Container operation and maintenance — docker [ps|inspect|top|attach|wait|export|port|rename|stat]
Container rootfs commands — docker [commit|cp|diff]
Mirror repository — docker [login|pull|push|search]
Local image management — docker [build|images|rmi|tag|save|import|load]
Container resource management — docker [volume|network]
System log information — docker [events|history|logs]

The meaning of common commands:

1 Introduction to docker commands

docker --help

Management commands:
Container Management
Image Management Image
Network Management

Order:
Attach to a running container
build Build an image based on Dockerfile
commit creates a new image based on the changes to the container
cp copies files/folders between the local file system and the container
create creates a new container
exec executes a command in the container
images lists images
kill Kill one or more running containers
logs Get the container logs
pause Pause all processes of one or more containers
ps lists all containers
pull pulls an image or repository to the registry
push Push an image or repository to the registry
rename Rename a container
restart Restart one or more containers
rm removes one or more containers
rmi deletes one or more images
run executes a command in a new container
search Search for images in Docker Hub
start starts one or more stopped containers
stats displays the real-time resource usage of a container
stop Stop one or more running containers
tag creates a new tag for the image
top shows all processes in a container
unpause Resume all paused processes in one or more containers

2. Image related

1. Pull the image

docker pull

2. View the image

docker images

3. Delete the image

docker rmi

Common parameters:
1. -f: Force deletion of running containers

4. Create an image

(1) Re-establish a new image after changing the source image

docker commit

Common parameters:
1. -m: This submission information
2. --author="" : author

(2) Use Dockerfile to build an image

docker build

Common parameters:
1. -tx/y:z: specifies the image namespace as x, the repository as y, and the tag as z

3. Container related

1. Run the container

docker run

Common parameters:
1. --name: Specify a name for the container
2. -it: Start an interactive container. This parameter provides an interactive shell for us and the container.
3. -d: Create a background container
4. -restart=always: Automatically restart after the container exits
5. -restart=on-failure:x: If the return value is non-zero when the container exits, it will try to restart x times
6. -px:y : host port: container port
7. -P: Randomly assign a port between 49000 and 49900
8.-v: Create a data volume
7. -n : Specify DNS
8. -h : Specify the hostname of the container
9. -e : Set environment variables
10. -m : Set the maximum memory usage of the container
11. --net: specifies the network connection type of the container, supporting bridge/host/none/container
12. --link=x: add a link to another container x
13. --expose=x: open port x

The containers created by docker create and docker run -it are interactive containers.

2. View the running container

docker ps 

Common parameters:
1. -a: View all containers
2. -l: only list the most recently created
3. -n=x: only list the last x created
3. -q: only list container id

3. Stop the container

docker stop //The method is gentle and stops the container slowly. docker kill //The method is simple and rough and stops the container immediately.

4. Delete the container

docker rm

Common parameters:
1. -f: Force deletion of running containers
2. docker rm `docker ps -aq`: delete all containers

5. View container logs

docker logs

Common parameters:
1. -f: View logs in real time
2. --tail=x: View the last x lines
3. -t: View the time when the log was generated

6. View container process

docker top

7. View container configuration information

docker inspect

Common parameters:
1. -f='{{x}}': View x configuration

8. Enter the container

(1) Entering the interactive container

docker attack

Common parameters:
1. -f: Force deletion of running containers
2. docker rm `docker ps -aq`: delete all containers

(2) Entering the background container

docker exec

Common parameters:
1. -it container id /bin/bash: enter the background container

Dockerfile

This is the end of this article about the summary of commonly used docker commands (recommended). For more related commonly used docker commands, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Basic introduction and use of Docker container image related commands
  • Summary of essential Docker commands for developers
  • Summary and analysis of commonly used Docker commands and examples
  • Detailed explanation of common Docker commands
  • Summary of common docker commands
  • A complete guide to the Docker command line (18 things you have to know)
  • Summary of learning Docker commands in one article
  • Introduction to common Docker commands

<<:  How to optimize MySQL group by statement

>>:  JavaScript to implement a simple shopping form

Recommend

Vue sample code for online preview of office files

I'm working on electronic archives recently, ...

Use of Linux ln command

1. Command Introduction The ln command is used to...

Detailed explanation of Linux netfilter/iptables knowledge points

Netfilter Netfilter is a packet processing module...

Using jQuery to implement the carousel effect

This article shares the specific code for impleme...

Vue implements automatic jump to login page when token expires

The project was tested these days, and the tester...

Basic statements of MySQL data definition language DDL

MySQL DDL statements What is DDL, DML. DDL is dat...

Tips on setting HTML table borders

For many people who are new to HTML, table <ta...

Detailed explanation of BOM and DOM in JavaScript

Table of contents BOM (Browser Object Model) 1. W...

CentOS 8 Installation Guide for Zabbix 4.4

Zabbix server environment platform ZABBIX version...

Negative margin function introduction and usage summary

As early as in the CSS2 recommendations in 1998, t...

Flex layout realizes the layout mode of upper and lower fixed and middle sliding

This article mainly introduces the layout method ...