Creating a custom base image

Writing the Dockerfile

The Dockerfile in the minimal-ade project shows a minimal example of how to create a custom base image:

FROM ubuntu:bionic

RUN apt-get update && \
    echo 'Etc/UTC' > /etc/timezone && \
    ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
    apt-get install -y \
        sudo \
        locales \
        tzdata \
  && rm -rf /var/lib/apt/lists/*
RUN locale-gen en_US.UTF-8; dpkg-reconfigure -f noninteractive locales
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

# After apt install sudo
RUN echo 'ALL ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

COPY env.sh /etc/profile.d/ade_env.sh
COPY entrypoint /ade_entrypoint
ENTRYPOINT ["/ade_entrypoint"]
CMD ["/bin/sh", "-c", "trap 'exit 147' TERM; tail -f /dev/null & while wait ${!}; test $? -ge 128; do true; done"]

Let’s walk through it:

  1. An existing Docker image

    FROM ubuntu:bionic
    
  2. Some convenience programs and requirements of the entrypoint:

    RUN apt-get update && \
        echo 'Etc/UTC' > /etc/timezone && \
        ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
        apt-get install -y \
            sudo \
            locales \
            tzdata \
      && rm -rf /var/lib/apt/lists/*
    RUN locale-gen en_US.UTF-8; dpkg-reconfigure -f noninteractive locales
    ENV LANG en_US.UTF-8
    ENV LANGUAGE en_US.UTF-8
    ENV LC_ALL en_US.UTF-8
    
    # After apt install sudo
    RUN echo 'ALL ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
    
  3. env.sh:

    COPY env.sh /etc/profile.d/ade_env.sh
    
    • Configures the default environment on ade enter

    • Source the .env.sh files provided by volumes (see Creating a custom volume)

  4. entrypoint :

    COPY entrypoint /ade_entrypoint
    ENTRYPOINT ["/ade_entrypoint"]
    

    See also The entrypoint file.

  5. CMD:

    CMD ["/bin/sh", "-c", "trap 'exit 147' TERM; tail -f /dev/null & while wait ${!}; test $? -ge 128; do true; done"]
    
    • This command attaches a process to PID 1 which will keep the container running even if no one is attached to the container

Building the image

Once the Dockerfile is ready, build the image by running docker build in the directory that contains the Dockerfile:

docker build -t <image_name>:<tag> .

Add --label ade_image_commit_sha=<git-hash> and/or --label ade_image_commit_tag=<git-tag> to embed VCS information in the Docker image:

docker build \
  --label ade_image_commit_sha=<git-hash> \
  --label ade_image_commit_tag=<git-tag> \
  -t <image_name>:<tag> .

For more information, see the docker build documentation

Using the image

To use the image, add it to the .aderc file as the first entry in ADE_IMAGES:

export ADE_IMAGES="
   <image_name>:<tag>
   ...
"

For more information, see The .aderc File