Docker hint

Today, 18th May 2022, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putin’s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

Most popular docker commands in one hint here.

Post in the comments if you have what to add to this list!

Build an image from Dockerfile when you are in a folder with it and start the container instantly (and run bash inside of it):

docker run --rm -it $(docker build -q .) bash

Stop all containers on the host in one command:

docker kill $(docker ps -q)

Attach to the existing running container and run bash there:

docker exec -it stack-master_nginx_1 bash

To get the container name, run:

docker ps

Example output:

CONTAINER ID   IMAGE               COMMAND                  CREATED             STATUS             PORTS  NAMES
3dc80e13f898   stack-master_nginx  "/docker-entrypoint.…"   About an hour ago   Up About an hour           stack-master_nginx_1

To restart the container:

docker restart master_nginx_1

Enable docker build kit which is the simplest way to build images faster:


Note: this works only for Docker 18.09+

To get daemon version:

docker info | grep 'Server Version'

Universal space cleaner which removes:

docker system prune -a -f

Remove only dangling images silently:

docker 2>/dev/null 1>&2 rmi $(docker images -f "dangling=true" -q) || true

Ivan Borshchov profile picture
Nov 16, 2021
by Ivan Borshchov
Did it help you?
Yes !

Best related