【Cloud Native】Induction of commonly used docker commands

Summary of common docker commands


Preface

    随着云原生技术不断落地,日常运维过程中存在docker相关命令操作,本文主要介绍docker日常命令用途及使用方法。

1. Container operation

To see which containers are running

docker ps

View all containers (including stopped ones)

docker ps -a

Start, stop, restart containers

docker start|stop|restart $dockerid 

into the running container

docker exec -it $dockerid /bin/bash

Export container as image

docker commit $dockerid 

Delete container

docker rm $dockerid

Container status

docker stats $dockerid

Container metadata

docker inspect $dockerid

2. Container file operations

2.1 Copy the file from the host to the container

docker cp /tmp/error.log $dockerid:/tmp/

Among them, /tmp/error.log is the original file of the host machine, and $dockerid:/tmp/ is the container id: target directory

2.2 Copy the container's files from the container to the host

docker cp $dockerid:/tmp/error.log /tmp/

Among them, $dockerid:/tmp/error.log is the container id: the original file path, and /tmp/ is the host directory


3. Log operation

View container logs

docker logs $dockerid

View real-time container logs

docker logs -f $dockerid

clear log

docker logs --tail=0 $dockerid

4. Container space operation

See how much space a container is using

docker system df

How to clean everything in Docker, use this command with caution

docker system prune -a**

Only clean up dangling images

docker image prune -a

Clean up unused volumes/

docker volume prune

Clean up stopped containers

docker container prune

Supongo que te gusta

Origin blog.csdn.net/weixin_40012925/article/details/132487452
Recomendado
Clasificación