Here are some useful Docker snippets
Containers
Task |
Command |
Kill all running containers |
docker kill $(docker ps -q) |
Stop all containers |
docker stop $(docker ps -a -q) |
Remove all containers |
docker rm $(docker ps -a -q) |
Remove single container |
docker stop < container id > |
Images
Task |
Command |
Remove all images |
docker rmi $(docker images -q) |
Remove single image |
docker rmi < image id > |
Remove ‘dangling’ or untagged images
1
| docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
|
Add or Run a bash command in your Dockerfile:
1
| RUN /bin/bash -c "echo 'hello world'"
|
Docker-Compose
Run a single container based on Docker-compose
1
| docker-compose run < container name > < command >
|