Dockerfile Example: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Dockerfile =Example= <pre> # # Example of very simple Dockerfile based on minimalistic BusyBox base image # Please read through each com...")
 
Line 5: Line 5:
=Example=
=Example=


<pre>
#
#
# Example of very simple Dockerfile based on minimalistic BusyBox base image
# 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
# 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"


#
#
# Docker will pull from docker.io if base image does not already exist in local Docker repo
# Define two environment variables: NAME and TARGET_DIR
#
# Value of env variables can be modified at container startup using -e parameter
FROM busybox
#
ENV NAME="NovaOrdis OpenShift Test Environment" \
    TARGET_DIR="/var/novaordis"


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


#
#
# The LABEL instruction adds metadata to an image. A LABEL is a key-value pair.
# /usr/local/bin/ is included in the root user's $PATH, so copy our shell script to this directory
#
#
LABEL version="1.0" \
COPY run-loop.sh /usr/local/bin/run-loop.sh
      description="A project that creates a custom Docker image based on a BusyBox base image"


#
#
# Define two environment variables: NAME and TARGET_DIR
# Ensure that shell script added to image is set as executable
# Value of env variables can be modified at container startup using -e parameter
#
#
RUN chmod 755 /usr/local/bin/run-loop.sh
ENV NAME="NovaOrdis OpenShift Test Environment" \
    TARGET_DIR="/var/novaordis"
#
 
# Create directory and define it as a container mount point. Our shell script will write output
#
# to local filesystem at this mount point.
# Docker is to execute all subsequent commands in this file as BusyBox's root user
#
#
CMD mkdir $TARGET_DIR
USER root
VOLUME $TARGET_DIR
 
#
#
# /usr/local/bin/ is included in the root user's $PATH, so copy our shell script to this directory
# At startup, this container should run a single command. Our script uses the command line
#
# parameters passed as part of $NAME env var
COPY run-loop.sh /usr/local/bin/run-loop.sh
#
 
CMD /usr/local/bin/run-loop.sh $NAME
#
# 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.
#
CMD 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
</pre>

Revision as of 05:12, 20 November 2017

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.
#
CMD 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