Detailed explanation of common Docker commands

Detailed explanation of common Docker commands

1. Help Command

1. View the current Docker version

docker version

2. Display Docker system information, including images and container numbers

docker info

3. View the help document, similar to the Man command of CentOS

docker --help

2. Mirror command

1. View the image on the local host:

#List all local images (including intermediate image layers)
docker images -a 
#Only display the image ID
docker images -q 
#Show complete image information docker images --no-trunc

2. Search for images: https://hub.docker.com

docker search [OPTIONS] image nameOPTIONS: --no-trunc: Display the complete image description -s: List images with a collection count not less than the specified value --automated: Only list images of the automated build type;

2. Download the image

docker pull image name [:TAG]
TAG: The default version is latest.

3. Delete the image

#Delete a single docker rmi image name or ID
docker rmi -f image ID
#Batch delete docker rmi -f image name 1: TAG image name 2: TAG 
#Delete all images docker rmi -f $(docker images -qa)

3. Container Commands

1. Create and start a container

docker run [OPTIONS] IMAGE_NAME [COMMAND] [ARG...]

OPTIONS Description
–name="Container new name" : Specify a name for the container;
-d : Run the container in the background and return the container ID, which means starting a daemon container;
-i : Run the container in interactive mode, usually used with -t;
-t : reallocate a pseudo input terminal for the container, usually used with -i;
-P: Random port mapping;
-p: Specify port mapping ( hostPort:containerPort )

2. View all currently running containers

docker ps [OPTIONS]

OPTIONS Description
-a : List all currently running containers + containers that have been run in the past
-l : Display recently created containers
-n : Display the last n created containers
-q : Silent mode, only display container number
--no-trunc : Do not truncate output

3. Exit the container

exit The container stops and exits ctrl+P+Q The container does not stop and exits

4. Start the container

docker start container ID or container name

5. Restart the container

docker restart container ID or container name

6. Stop the container

docker stop container ID or container name

7. Force stop the container

docker kill container ID or container name

8. Delete the stopped container

docker rm container ID
#Delete multiple containers at once docker rm -f $(docker ps -a -q)

9. Enter the running container and interact with it from the command line

Start a new process in the container and open the terminal

docker exec -it container ID /bin/sh

Directly enter the terminal of the container startup command, and no new process will be started

docker attach container id

10. Copy files from the container to the host

docker cp container ID: path in container destination host path

11. Copy files from the host to the container

docker cp Host file or directory to be copied Container name: container file or directory

12. View the container mount directory

docker inspect container_name
docker inspect container_id

This directory is the location of your container data volume

insert image description here

13. Related image startup commands

RabbitMQ:

docker run -d --hostname localhost --name rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:management

This is the end of this article about common Docker commands. For more information about common 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
  • Summary of common docker commands
  • Summary of common docker commands (recommended)
  • 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 support Webdings fonts in Firefox

>>:  Implementation example of JS native double-column shuttle selection box

Recommend

Practical MySQL + PostgreSQL batch insert update insertOrUpdate

Table of contents 1. Baidu Encyclopedia 1. MySQL ...

Two methods of restoring MySQL data

1. Introduction Some time ago, there were a serie...

JS gets the position of the nth occurrence of a specified string in a string

Learn about similar methods for getting character...

MySQL cursor principle and usage example analysis

This article uses examples to explain the princip...

Detailed explanation of the principle of js Proxy

Table of contents What is Proxy Mode? Introducing...

Install and configure ssh in CentOS7

1. Install openssh-server yum install -y openssl ...

Summary of knowledge points about covering index in MySQL

If an index contains (or covers) the values ​​of ...

What does mysql database do

MySQL is a relational database management system ...

js to realize login and registration functions

This article example shares the specific code of ...

Example of how to upload a Docker image to a private repository

The image can be easily pushed directly to the Do...

Using Vue3 (Part 1) Creating a Vue CLI Project

Table of contents 1. Official Documentation 2. Cr...

18 Amazing Connections Between Interaction Design and Psychology

Designers need to understand psychology reading n...