Images

Basic Dockerfile example

LABEL maintainer="Yaroslav Grebnov" version="1.0"
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf

Multistage build Dockerfile example

Create an image from scratch using Dockerfile

Create an image using docker commit

Use variables in Dockerfile

Variables in Dockerfile to be used during image building

ARG

Not cached

Variables in Dockerfile to be used during container running

ENV

Cached

Variables in Dockerfile to be used during both, image building and container running

ARG var ENV var=${var}

Variable expansion in Dockerfile

COPY {var,,}

Build an image using Dockerfile

Build an image an push it to registry

Check how an image was built

Remove dangling images

docker rmi $(docker image ls -f "dangling=true" -q)

Command explantion:

  • docker image ls lists images
  • -f stands for filter. So, -f "dangling=true" selects only the dangling images
  • -q stands for quiet, which means that only the images IDs (hashes) are returned
  • docker rmi removes a list of selected images