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

MySQL select, insert, update batch operation statement code examples

In projects, batch operation statements are often...

A comprehensive summary of frequently used statements in MySQL (must read)

The knowledge points summarized below are all fre...

How to use Linux to calculate the disk space occupied by timed files

Open the scheduled task editor. Cent uses vim to ...

5 solutions to CSS box collapse

First, what is box collapse? Elements that should...

Detailed explanation of the problem when combining CSS ellipsis and padding

Text truncation with CSS Consider the following c...

Mysql5.6.36 script compilation, installation and initialization tutorial

Overview This article is a script for automatical...

How to elegantly implement WeChat authorized login in Vue3 project

Table of contents Preface Prepare Implementation ...

Docker Basics

Preface: Docker is an open source application con...

Tutorial on installing Tomcat server under Windows

1 Download and prepare First, we need to download...