Docker Command Reference

Essential Docker commands with explanations and examples

Running Containers Resource Management Attaching Shells Cleaning Up

Running and Stopping Containers

Command Description Action
docker pull [imageName] Pull an image from a registry
docker run [imageName] Run containers
docker run -d [imageName] Detached mode
docker start [containerName] Start stopped containers
docker ps List running containers
docker ps -a List running and stopped containers
docker stop [containerName] Stop containers
docker kill [containerName] Kill containers
docker image inspect [imageName] Get image info

Usage Tips

Image Management

Use docker images to list all downloaded images on your system.

Container Identification

You can use either container ID or name with Docker commands. Names are easier to remember!

Resource Management

Command Description Action
docker run --memory="256m" nginx Max memory
docker run --cpus=".5" nginx Max CPU

Attaching Shells

Command Description Action
docker run -it nginx -- /bin/bash Attach shell
docker run -it -- microsoft/powershell:nanoserver pwsh.exe Attach Powershell
docker container exec -it [containername] -- bash Attach to a running container

Cleaning Up

Command Description Action
docker rm [containerName] Removes stopped containers
docker rm $(docker ps -a -q) Removes all stopped containers
docker images Lists images
docker rmi [imageName] Deletes the image
docker system prune -a Removes all images not in use by any containers