Packaging and containerisation of software so that they could run on any hardware

Components

  • Docker File
    • Blueprint for building a docker image.
  • Docker Image
    • Template for running docker containers.
  • Docker Container
    • The actual running process.
  • Docker Compose
    • Tool for running multiple docker containers at the same time.

Writing Dockerfile

Dockerfile InstructionExplanation
FROMTo specify the base image which can be pulled from a container registry( Docker hub, GCR, Quay, ECR, etc)
RUNExecutes commands during the image build process.
ENVSets environment variables inside the image. It will be available during build time as well as in a running container. If you want to set only build-time variables, use ARG instruction.
COPYCopies local files and directories to the image
EXPOSESpecifies the port to be exposed for the Docker container.
ADDIt is a more feature-rich version of the COPY instruction. It also allows copying from the URL that is the source and tar file auto-extraction into the image. However, usage of COPY command is recommended over ADD. If you want to download remote files, use curl or get using RUN.
WORKDIRSets the current working directory. You can reuse this instruction in a Dockerfile to set a different working directory. If you set WORKDIR, instructions like RUN​, CMD​, ADD​, COPY​, or ENTRYPOINT​ gets executed in that directory.
VOLUMEIt is used to create or mount the volume to the Docker container
USERSets the user name and UID when running the container. You can use this instruction to set a non-root user of the container.
LABELIt is used to specify metadata information of Docker image
ARGIs used to set build-time variables with key and value. the ARG variables will not be available when the container is running. If you want to persist a variable on a running container, use ENV.
CMDIt is used to execute a command in a running container. There can be only one CMD, if multiple CMD there then it only applies to the last one. It can be overridden from the Docker CLI.
ENTRYPOINTSpecifies the commands that will execute when the Docker container starts. If you don’t specify any ENTRYPOINT, it defaults to /bin/sh -c​. You can also override ENTRYPOINT using the --entrypoint​ flag using CLI. Please refer CMD vs ENTRYPOINT for more information.

Docs / Resources