Image Management
List local images
docker image ls
Build an image
docker build . -t image:tag
Build images locally using unique tagging
# Leveraging PowerShell
docker build . -t image:$(get-date -Format "yyyyMMddHHmmss")
Remove images
# Option 1
docker image rm image:tag
# Option 2
docker rmi image:tag
# Option 3
docker rmi <imageid>
# Option 4
docker rmi <only-first-characters-of-image-id>
Inspect image content
# Option 1
docker run -it image:tag sh
# Option 2
docker run -it --entrypoint sh image:tag
# Option 3
docker image history --no-trunc image:tag > image_history
Container Management
List running containers
docker container ls
Run interactively and remove afterward
docker run -it --rm image:tag sh
docker run --interactive --tty --rm image:tag sh
Exposing ports
docker run -it -p <localPort>:<containerPort> image:tag
Stop and remove a running container
# Instead of
docker container stop foobar
docker container rm foobar
# Use ...
docker rm foobar --force
# Or
docker rmi -f foobar
Volumes
Bind mount a single file into a container
podman run --rm -ti -v c:\\temp\\fluent-bit.conf:/etc/fluent-bit.conf cr.fluentbit.io/fluent/fluent-bit:2.2.0 -c /etc/fluent-bit.conf
Misc
Difference between Image ID and digest
- The digest is a hash of the manifest, introduced in Docker registry v2
- The image ID is a hash of the local image JSON configuration
Run Postgres locally
docker run -p 5432:5432 -v postgres-11-volume:/var/lib/postgresql/data --env POSTGRES_PASSWORD=postgres --name postgres-11 postgres:11 --restart=always