Command practice of docker client

docker (base command)

The base command for the Docker CLI.

docker ps

docker ps

List local containers
List containers

usage

docker ps [OPTIONS]

example

// Show both running and stopped containers
docker ps -a
docker ps -a | grep insurance
// 结果
CONTAINER ID        IMAGE                                                               COMMAND                  CREATED             STATUS              PORTS               NAMES
d887a50cf343        hub.uban360.com/basic-x86/jar:202112201122                          "sh run-java.sh"         2 hours ago         Up 2 hours                              access_insurance-org-user_1

docker run

docker run

Run a command in a new container
Run a command in a new container

usage

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

example

// Assign name and allocate pseudo-TTY (--name, -it)
docker run --name test -it debian

docker logs

docker logs


Fetch the logs of a container

usage

docker logs [OPTIONS] CONTAINER

example

// 应用启动报错日志
docker logs afe977b1eca6

docker restart

docker restart

Restart one or more containers
Restart one or more containers

usage

docker restart [OPTIONS] CONTAINER [CONTAINER...]

example

// restart one or more containers
docker restart afe977b1eca6

docker exec

docker exec


Run a command in a running container

usage

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

example

// execute an interactive bash shell on the container
// 登录到容器实例的控制台,排查具体的CPU、内存使用率高等问题
docker exec -it afe977b1eca6 bash

docker stats

docker stats


Display a live stream of container(s) resource usage statistics

usage

docker stats [OPTIONS] [CONTAINER...]

example

docker stats a977cf6ef0a0
// 查看哪些容器实例的CPU、内存使用率较高
CONTAINER ID        NAME                 CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
a977cf6ef0a0        access_doconline_1   115.82%             723.4MiB / 15.05GiB   4.69%               0B / 0B             0B / 796kB          54

docker stop

docker stop

Stop one or more running containers
Stop one or more running containers

usage

docker stop [OPTIONS] CONTAINER [CONTAINER...]

example

// 手动下线服务
docker stop 725db3e14f46

docker image

docker image

Manage images
Manage images

usage

docker image COMMAND

docker image ls

docker image ls

List
images List images

usage

docker image ls [OPTIONS] [REPOSITORY[:TAG]]

example

docker image ls
// 结果
REPOSITORY                               TAG                     IMAGE ID            CREATED             SIZE
registry.shinemo.net:5000/redis          5.0.9-2                 20d6ecbe184f        2 years ago         123MB

Guess you like

Origin blog.csdn.net/shupili141005/article/details/128675327