Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the common commands of the Docker container

Shulou Source: shulou.com Published: 2022-06-03 05:01:08 11月16日 Update

This article shares with you common commands about Docker containers. The editor thought it was very practical, so I shared it with you to learn. The following information is a common command for Docker containers.

1. View all mirrors

Docker image ls abbreviation: docker images

two。 View all running containers

Docker container ls abbreviation: docker ps

3. View all containers

Docker container ls-an abbreviation: docker ps-a

4. Delete Container

Docker rm container container ID abbreviation: docker rm container ID

5. Delete Mirror

Docker image rm image ID abbreviation: docker rmi image ID

6. If there are many containers to be deleted, list all the container ID

Docker container ls-a | awk {'print$1'} / / output the first column abbreviated: docker container ls-aq delete all containers: docker rm $(docker container ls-aq)

7. Delete all exited containers

Docker container ls-f "status=exited" / / list all exit containers abbreviated: docker ps-f "status=exited" docker container ls-f "status=exited"-Q / / list all exit containers ID abbreviation: docker ps-f "status=exited"-qdocker rm $(docker container ls-f "status=exited"-Q) abbreviation: docker rm $(docker ps-f "status=exited"-Q)

8. Create a container by mirroring

Docker run-- name-d-p 8080 ID explains:-- name gives the container an alias-d for background operation-p container port and host port mapping

9. Create an image by the container (because the container may change during use, for example: a centos container with the vim plug-in installed)

Docker container commit abbreviation: docker commit Note: this is not recommended

10. Create a mirror through Dockerfile

Docker image build abbreviation: docker build

11. Enter a container that is running

Docker exec-it container name / bin/bash (or / bin/sh)

twelve。 Copy the files in the container to the host

# docker cp container name: the path of the file to be copied in the container should be copied to the corresponding path of the host docker cp nginx:/usr/share/nginx/nginx.tar / usr/local

13. Copy the files from the host to the container

# File path to be copied by docker cp Container name: to copy to the corresponding path docker cp / usr/local/nginx.tar nginx:/usr/share in the container

This is the end of the common commands about the Docker container. I hope the above can be of some help to you. If you like this article, you might as well share it for more people to see.

Tags: Container abbreviation image copy host host file path command common running in progress port article utility content alias name background plug-in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Huawei Xiaomi vpn