Example Dockerfiles

Java application on Ubuntu 16

FROM ubuntu:16.04
MAINTAINER John Doe <author@email.com>

# Set environment variables
ENV version 0.1-alpha
ENV appname MyAwesomeApp
ENV runcmd java -jar /opt/${appname}-${version}.jar

# Install JDK8
RUN apt-get update && apt-get install -y openjdk-8-jre

# Copy the binary to /opt directory
COPY build/libs/${appname}-${version}.jar /opt/

# Open port 8080 for embedded Tomcat container
EXPOSE 8080

# Create the launch script
RUN echo ${runcmd} > /opt/launch.sh && chmod +x /opt/launch.sh

# Set launch script to fire off when docker launches container
ENTRYPOINT /opt/launch.sh

Example 2

FROM centos:centos6                                             // inherit from base image, local images have priority over remote images when building from an image.
MAINTAINER <First Last>
RUN yum -y update; yum clean all
RUN yum -y install httpd
RUN echo "Apache test site" >> /var/www/html/index.html
EXPOSE 80                                                       // making port 80 available publicly
RUN echo "/sbin/service httpd start" >> /root/.bashrc

Building an image from a Dockerfile

Build the image

docker build -t ddubson:centos6 .
$> docker build —file Dockerfile —tag mycustomimg/withservices:v1