Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes
#創建container docker container run #創建container nginx ,本地沒有找到直接去找docker hub 下載 並直接運行,並且是前台運行的container docker container run nginx #列出container ,ps 為較舊版本的命令 ,ls、ps效果是一樣的 docker container ls docker container ps #列出container 包含stop的container
docker container ps -a docker container ls -a docker ps -a #docker run 省略container 是較舊的寫法 docker container run nginx docker run nginx #停止容器 docker container stop [NAMES] or [Container id] docker stop [NAMES] or [Container id] #刪除容器 docker container rm [NAMES] or [Container id] docker rm [NAMES] or [Container id]
4.1. Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ docker container run nginx $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 343fd4031609 nginx "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 80/tcp xenodochial_clarke $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 343fd4031609 nginx "/docker-entrypoint.…" 14 seconds ago Up 13 seconds 80/tcp xenodochial_clarke $ docker container stop 34 34 $ docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 343fd4031609 nginx "/docker-entrypoint.…" 29 seconds ago Exited (0) 5 seconds ago xenodochial_clarke d9095daa8bcf nginx "/docker-entrypoint.…" 28 minutes ago Exited (0) 28 minutes ago suspicious_shamir $ docker container rm 34 34 $ docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d9095daa8bcf nginx "/docker-entrypoint.…" 28 minutes ago Exited (0) 28 minutes ago suspicious_shamir $
5. 命令行小技巧之批次操作
5.1. 批次停止
先查詢目前的清單如下
1 2 3 4 5 6 7
$ docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cd3a825fedeb nginx "/docker-entrypoint.…" 7 seconds ago Up 6 seconds 80/tcp mystifying_leakey 269494fe89fa nginx "/docker-entrypoint.…" 9 seconds ago Up 8 seconds 80/tcp funny_gauss 34b68af9deef nginx "/docker-entrypoint.…" 12 seconds ago Up 10 seconds 80/tcp interesting_mahavira 7513949674fc nginx "/docker-entrypoint.…" 13 seconds ago Up 12 seconds 80/tcp kind_nobel
方法1
1 2
#刪除多個container ,以下為例刪除4個container docker container stop af 87 c2 4c