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
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
Add or Run a bash command in your Dockerfile:
RUN /bin/bash -c "echo 'hello world'"
Docker-Compose
Run a single container based on Docker-compose
docker-compose run < container name > < command >