docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker images -q | xargs docker rmi
docker exec -i -t <container_id> bash
docker-compose -f docker-compose-dev.yml run -d --service-ports --rm --no-deps api npm start
-d
- Detached mode: Run container in the background-rm
- Remove container after run. Ignored in detached mode--no-deps
- Don't start linked services--service-ports
- Run command with the service's ports enabled and mapped to the host
docker-compose restart api
docker-compose kill api
docker system prune -a --volumes
In older versions of Docker (and this still works today), you can delete dangling images on their own by running docker rmi -f $(docker images -f "dangling=true" -q)
.
But with newer versions of Docker (1.13+) there’s an even better command called docker system prune
which will not only remove dangling images but it will also remove all stopped containers, all networks not used by at least 1 container, all dangling images and build caches.
The -a tells Docker to remove all unused images, without it Docker only removes dangling (untagged) images. Volumes will not be pruned by default if you don't include the --volumes flag.