Dockerfile Example

From NovaOrdis Knowledge Base
Revision as of 01:14, 1 February 2018 by Ovidiu (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Example

#
# Example of very simple Dockerfile based on minimalistic BusyBox base image
# Please read through each comment to gain a better understanding of what this Dockerfile does
#

#
# Docker will pull from docker.io if base image does not already exist in local Docker repo
#
FROM busybox

MAINTAINER "Nova Ordis"

#
# The LABEL instruction adds metadata to an image. A LABEL is a key-value pair.
#
LABEL version="1.0" \
      description="A project that creates a custom Docker image based on a BusyBox base image"

#
# Define two environment variables: NAME and TARGET_DIR
# Value of env variables can be modified at container startup using -e parameter
#
ENV NAME="NovaOrdis OpenShift Test Environment" \
    TARGET_DIR="/var/novaordis"

#
# Docker is to execute all subsequent commands in this file as BusyBox's root user
#
USER root

#
# /usr/local/bin/ is included in the root user's $PATH, so copy our shell script to this directory
#
COPY run-loop.sh /usr/local/bin/run-loop.sh

#
# Ensure that shell script added to image is set as executable
#
RUN chmod 755 /usr/local/bin/run-loop.sh

#
# Create directory and define it as a container mount point. Our shell script will write output
# to local filesystem at this mount point.
#
RUN mkdir $TARGET_DIR
VOLUME $TARGET_DIR

#
# At startup, this container should run a single command. Our script uses the command line
# parameters passed as part of $NAME env var
#
CMD /usr/local/bin/run-loop.sh $NAME