Docker cheatsheet.
docker image build -t IMAGE:1.0.0 .
docker build -t IMAGE:1.0.0 . # Build IMAGE:1.0.0 using Dockerfile in .
docker images
docker image ls # List all locally stored images
docker image rm IMAGE:1.0.0 # Remove local IMAGE:1.0.0
docker image prune [-a] # Remove local unused dangling/[all] images
docker image history IMAGE # Show history of IMAGE
NOTE: Dangling image is image of fs layer that is not associated with any of tagged images. Unused image is any image that is not use by any container.
docker run [--rm] IMAGE:1.0.0 # Run IMAGE:1.0.0 and clean up
docker run -d IMAGE:1.0.0 # Run IMAGE:1.0.0 in background
docker run -p DEST:SRC IMAGE:1.0.0 # Run IMAGE:1.0.0; expose port SRC as DEST
docker run --name NAME IMAGE:1.0.0 # Run IMAGE:1.0.0 as NAME
docker ps [-a]
docker container ls [-a] # See running [-a] containers
docker stop|kill NAME # Send SIGTERM|SIGKILL to container
docker rm -f $(docker ps -aq) # Delete all (also stopped) containers
Run in background a container referred to as NAME
using image IMAGE:1.0.0
exposing guest port SRC
on host running Docker as DEST
:
docker run -d --name NAME -p DEST:SRC IMAGE:1.0.0
docker exec -it NAME CMD # Run CMD interactively in container NAME
docker attach NAME # Attach terminal to container NAME
docker container logs NAME
docker logs NAME # Show logs for container NAME
docker logs --tail N NAME # Show last N lines of logs for NAME
Get bash
in running container referred to as NAME
:
docker exec -it NAME /bin/bash
- Enable Expose daemon on tcp://localhost:2375 without TLS
- In WSL
DOCKER_HOST=127.0.0.1:2375
- To be able to pull images from Docker hub (to be able to
docker login
) in WSL inside your$PATH
createdocker-credential-desktop
executable file with following contents:#!/bin/sh /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker-credential-desktop.exe $@