Loading

docker命令行的使用

在Docker Hub上查询镜像:

pi@pi-NMH-WCX9:~$ docker search hello-world

在Docker Hub上拉取镜像:

pi@pi-NMH-WCX9:~$ docker pull hello-world

查看容器列表:

pi@pi-NMH-WCX9:~$ docker ps -a
CONTAINER ID   IMAGE                     COMMAND                  CREATED        STATUS       PORTS                                                 NAMES
8a024dac6f5d   hexo_ubuntu22.04:latest   "/usr/local/bin/hexo…"   3 days ago     Up 3 hours   22/tcp, 0.0.0.0:8123->4000/tcp, [::]:8123->4000/tcp   hexo-server
c8d2b2520c00   8a3cdc4d1ad3              "/bin/bash"              3 months ago   Up 3 hours   127.0.0.1:8122->22/tcp                                loving_hertz

查看镜像列表:

# Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]
pi@pi-NMH-WCX9:~$ docker images
REPOSITORY           TAG       IMAGE ID       CREATED         SIZE
hexo_ubuntu22.04     latest    261dea374744   3 days ago      1.11GB
docker_ubuntu22-04   latest    2a0823f51114   3 months ago    3.42GB
ubuntu               22.04     8a3cdc4d1ad3   6 months ago    77.9MB
ubuntu               20.04     5f5250218d28   6 months ago    72.8MB
hello-world          latest    d2c94e258dcb   20 months ago   13.3kB

创建&运行容器:

# Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
# 注意:IMAGE 即可以是 IMAGE_ID,也可以是 REPOSITORY:TAG , 或 REPOSITORY 
pi@pi-NMH-WCX9:~$ docker run hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

在运行容器执行命令:

# Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
#Execute a command in a running container
#
#Aliases:
#  docker container exec, docker exec
#
#Options:
#  -d, --detach               Detached mode: run command in the background
#      --detach-keys string   Override the key sequence for detaching a container
#  -e, --env list             Set environment variables
#      --env-file list        Read in a file of environment variables
#  -i, --interactive          Keep STDIN open even if not attached
#      --privileged           Give extended privileges to the command
#  -t, --tty                  Allocate a pseudo-TTY
#  -u, --user string          Username or UID (format: "<name|uid>[:<group|gid>]")
#  -w, --workdir string       Working directory inside the container


删除容器:

# Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]
# 注意:CONTAINER 即容器ID,一般前4位数就可以代表一个容器
pi@pi-NMH-WCX9:~$ docker rm d3e2
d3e2

删除镜像:

# Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]
pi@pi-NMH-WCX9:~$ docker rm d2c9
d2c9
posted @ 2025-12-22 21:50  eiSouthBoy  阅读(2)  评论(0)    收藏  举报