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

Example of how to quickly delete a 2T table in mysql in Innodb

Preface This article mainly introduces the releva...

Linux/Mac MySQL forgotten password command line method to change the password

All prerequisites require root permissions 1. End...

Docker Detailed Illustrations

1. Introduction to Docker 1.1 Virtualization 1.1....

How to use libudev in Linux to get USB device VID and PID

In this article, we will use the libudev library ...

Practice of deploying web applications written in Python with Docker

Table of contents 1. Install Docker 2. Write code...

A brief discussion on common operations of MySQL in cmd and python

Environment configuration 1: Install MySQL and ad...

A detailed introduction to seata docker high availability deployment

Version 1.4.2 Official Documentation dockerhub st...

A Brief Analysis of MySQL Connections and Collections

Join query A join query refers to a matching quer...

MySQL Community Server compressed package installation and configuration method

Today, because I wanted to install MySQL, I went ...

How to redirect nginx directory path

If you want the path following the domain name to...

MySQL decimal unsigned update negative numbers converted to 0

Today, when verifying the concurrency problem of ...

Is it true that the simpler the web design style, the better?

Original address: http://www.webdesignfromscratch...

A detailed introduction to the netstat command in Linux

Table of contents 1. Introduction 2. Output Infor...