Essential Docker commands with explanations and examples
| 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 |
Use docker images to list all downloaded images on your system.
You can use either container ID or name with Docker commands. Names are easier to remember!
| Command | Description | Action |
|---|---|---|
| docker run --memory="256m" nginx | Max memory | |
| docker run --cpus=".5" nginx | Max CPU |
| 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 |
| 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 |