~/snippets/docker
Published on

Docker

271 words2 min read

Docker CLI

See Full CLI reference for a comprehensive documentation

Getting information

CommandResult
docker versionGet version info about docker
docker infoGet overview of different docker info
docker psList running containers
docker ps -aList all existing containers
docker system dfGet storage usage of Docker
docker system topGet running process of a container
docker statsList live stream of container usage

Managing volumes

CommandResult
docker volume lsList all docker volumes
docker volume inspect VOLUME-IDList detailed volume information

Managing images

CommandResult
docker image lsList local images
docker rmi IMAGE-IDRemove specified image
docker image pruneRemove unused images
docker image prune -aRemove all images

Managing container

CommandResult
docker exec -it CONTAINER-ID [bash|sh]Log into the container
docker exec CONTAINER-ID commandExecutes command in the container

Clean up

CommandResult
docker stop $(docker ps)Stops all running containers
docker rm $(docker ps -q)Removes all containers
docker rm $(docker image ls -q)Deletes all images
docker builder pruneClear all the build cache

Alternative for Docker API 1.25 and greater:

CommandResult
docker system pruneRemoves unused data
docker system prune -aRemoves unused data but not just dangling images

Prevent a container from exiting

After starting a service via docker-compose Docker will shut it down if there is no process running. To prevent that you can call a "dummy" endless command - in this case by overriding the entrypoint with a simple ping.

entrypoint: ping localhost

Exec a command without entering a container

docker exec CONTAINER sh -c "cat /tmp/test"

Tag and push

registry.port/ is optional when pushing to duckerhub

docker login
docker build . -t foobar
docker tag foobar registry:port/name/foobar
docker push foobar registry:port/name/foobar