This skill explains how to use the Docker command line for common container workflows.
Use this skill when:
docker version or docker info works in the user’s shell.
If unsure, suggest the user run:
docker version
to confirm Docker is available.
docker ps, docker ps -a
docker images
docker logs
docker inspect
docker rm, docker rmi
docker system prune
docker volume rm
List running containers:
docker ps
List all containers (including stopped):
docker ps -a
Inspect a container in detail:
docker inspect <container-id-or-name>
List local images:
docker images
Inspect an image:
docker inspect <image-id-or-name>
Build an image from a Dockerfile in the current directory:
docker build -t <image-name>:<tag> .
Example:
docker build -t my-app:latest .
If the Dockerfile is in another directory:
docker build -t my-app:latest path/to/context
Run a container in the foreground:
docker run --rm -it <image-name>:<tag>
Run in detached mode (background service):
docker run -d --name <container-name> <image-name>:<tag>
Map ports from container to host:
docker run -d --name <container-name> -p 8080:80 <image-name>:<tag>
Mount a host directory into the container:
docker run -d --name <container-name> -v /host/path:/container/path <image-name>:<tag>
Stop a running container:
docker stop <container-id-or-name>
Remove a stopped container:
docker rm <container-id-or-name>
Stop and remove in one shot (two commands):
docker stop <container-id-or-name>
docker rm <container-id-or-name>
Remove an image by ID or name:
docker rmi <image-id-or-name>
Only suggest this when the user is sure the image is no longer needed.
See logs for a container:
docker logs <container-id-or-name>
Stream logs (follow):
docker logs -f <container-id-or-name>
Execute a shell inside a running container (if it has /bin/bash):
docker exec -it <container-id-or-name> /bin/bash
or with /bin/sh:
docker exec -it <container-id-or-name> /bin/sh
Only suggest these when the user explicitly wants cleanup:
docker container prune
docker image prune
docker system prune
For a more aggressive cleanup, but only if the user confirms:
docker system prune -a
-p host:container.
docker logs for errors.
共 1 个版本