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:

  •  all stopped containers
  •  all networks not used by at least one container
  •  all dangling images
  •  all dangling build cache
docker system prune -a -f

Remove only dangling images silently:

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