More instructions for the recipes

Who is maintaining the container?

MAINTAINER your name <your.email@domain.org>

WORKDIR: all subsequent actions will be executed in that working directory.

WORKDIR ~

ADD, COPY: add files to the image filesystem

Difference between ADD and COPY explained here and here

COPY: lets you copy a local file or directory from your host (the machine from which you are building the image)

ADD: same, but ADD works also for URLs, and for .tar archives that will be automatically extracted upon being copied.

# COPY source destination
COPY ~/.bashrc .

ENV, ARG: run and build environment variables

Difference between ARG and ENV explained here.

  • ARG values: available only while the image is built.
  • ENV values: available for the future running containers.

CMD, ENTRYPOINT: command to execute when generated container starts

The ENTRYPOINT specifies a command that will always be executed when the container starts. The CMD specifies arguments that will be fed to the ENTRYPOINT.

In the example below, when the container is run without an argument, it will execute echo "hello world".
If it is run with the argument nice it will execute echo "nice"

FROM ubuntu:18.04
ENTRYPOINT ["/bin/echo"]
CMD ["hello world"]

A more complex recipe (save it in a text file named Dockerfile:

FROM ubuntu:18.04

MAINTAINER Toni Hermoso Pulido <toni.hermoso@crg.eu>

WORKDIR ~

RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y wget

ENTRYPOINT ["/usr/bin/wget"]
CMD ["https://cdn.wp.nginx.com/wp-content/uploads/2016/07/docker-swarm-hero2.png"]