A collection of useful Docker commands.
Docker CLI #
Docker Run #
To run a container from an image, you can use the docker run command.
# Run a container in detached mode and map port 8080 to 80
docker run -d -p 8080:80 docker/welcome-to-dockerDocker ps #
To list all running containers.
docker psNote
Use the -a flag to show all containers, including those that have stopped.
docker ps -aDocker stop #
To stop a running container, you need its ID.
docker stop <container-id>Docker Image #
Here are some common commands for managing Docker images.
| Command | Description |
|---|---|
docker images | List all images |
docker images -a | List all images (including all) |
docker rmi <image-id> | Remove a specific image |
docker rmi <repo>:<tag> | Remove by repository:tag |
docker rmi <id1> <id2> | Remove multiple images |
docker image prune | Remove all dangling images |
docker image prune --all | Remove all unused images |