% docker # 删除镜像 Remove an image docker image rm # 从本地镜像存储中删除镜像 Delete an image from the local image store docker rmi # 清理无标签/悬空的镜像 Clean none/dangling images docker rmi $(docker images --filter "dangling=true" -q --no-trunc) # 强制清理无标签/悬空的镜像 Force clean none/dangling images docker rmi $(docker images --filter "dangling=true" -q --no-trunc) -f # 列出本地存储的所有镜像 List all images that are locally stored with the Docker engine docker images # 从当前目录的 Dockerfile 构建镜像并打标签 Build an image from the Dockerfile in the current directory and tag the image docker build -t : . # 从镜像仓库拉取镜像 Pull an image from a registry docker pull : # 通过 SIGTERM 停止正在运行的容器 Stop a running container through SIGTERM docker stop # 通过 SIGKILL 强制停止正在运行的容器 Stop a running container through SIGKILL docker kill # 列出所有网络 List the networks docker network ls # 列出正在运行的容器 List the running containers docker ps # 删除所有正在运行和已停止的容器 Delete all running and stopped containers docker rm -f $(docker ps -aq) # 在容器内创建一个新的 bash 进程并连接到终端 Create a new bash process inside the container and connect it to the terminal docker exec -it bash # 打印容器日志的最后 100 行 Print the last lines of a container's logs docker logs --tail 100 | less # 打印容器日志的最后 100 行并持续跟踪日志 Print the last lines of a container's logs and following its logs docker logs --tail 100 -f # 创建新网络 Create new network docker network create # 获取镜像 ID (示例命令,需根据实际情况调整) Get image ID (example command, adjust as needed) $ image_id: docker images --- --headers 1 --column 3 # 获取容器 ID (示例命令,需根据实际情况调整) Get container ID (example command, adjust as needed) $ container_id: docker ps --- --headers 1 --column 1 % docker-compose # 构建、创建、启动并附加到所有服务的容器 Builds, (re)creates, starts, and attaches to containers for all services docker-compose up # 构建、创建、启动并分离所有服务的容器 Builds, (re)creates, starts, and detaches to containers for all services docker-compose up -d # 构建、创建、启动并附加到指定服务的容器 Builds, (re)creates, starts, and attaches to containers for a service docker-compose up -d # 构建、创建、启动并分离指定服务的容器 Builds, (re)creates, starts, and detaches to containers for a service docker-compose up -d # 打印指定服务日志的最后 100 行 Print the last lines of a service’s logs docker-compose logs --tail 100 | less # 打印指定服务日志的最后 100 行并持续跟踪日志 Print the last lines of a service's logs and following its logs docker-compose logs -f --tail 100 # 停止并删除由 `up` 创建的容器和网络 Stops containers and removes containers, networks created by up docker-compose down