DEV Community

Cover image for Docker maintenance commands
Prabusah
Prabusah

Posted on • Updated on

Docker maintenance commands

Hello there!
Here are few Docker maintenance commands.

image commands
docker image ls - lists docker images.
docker images -aq -f 'dangling=true' | xargs docker rmi - removes all unused images.
docker rmi imageId - remove an image.
docker rmi -f imageId - force remove an image
docker rmi -f $(docker images -q) - deletes all images forcefully.

instance commands
docker ps - lists running docker instances.
docker ps -a - lists docker instances (including stopped).
docker stop containerId - stops the container (proper shutdown).
docker kill containerId - stops the container (not gracefully shutdown).
docker rm containerId - remove a stopped container.
docker rm $(docker ps -a -q) - removes all stopped containers.

execution commands
docker exec -it containerName /bin/bash - Use this to interact with already running container.
docker run -it --entrypoint=/bin/bash containerName - Starts the docker and lands user in shell.
docker logs -t containerName - shows logs even for container with exited status.

Image by Alexander Fox | PlaNet Fox from Pixabay

Top comments (0)