Skip to content

Instantly share code, notes, and snippets.

@josh-padnick
Created February 17, 2015 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save josh-padnick/597f62417241524794d8 to your computer and use it in GitHub Desktop.
Save josh-padnick/597f62417241524794d8 to your computer and use it in GitHub Desktop.
Dockerfile Example
# MINIMAL DOCKER IMAGE FOR RUNNING A MICROSERVICE
FROM ohmygoshjosh/busybox
MAINTAINER Josh Padnick <josh@tinysteps.co>
# MICROSERVICE ENV VARS
# ------------------------------------------------------------------------------
ENV MICROSERVICE_NAME lemon
# INSTALL JAVA
# Inspired by https://registry.hub.docker.com/u/jeanblanchard/busybox-java/dockerfile/
# ------------------------------------------------------------------------------
# Install cURL
RUN opkg-install curl
# Java Version
ENV JAVA_VERSION_MAJOR 8
ENV JAVA_VERSION_MINOR 31
ENV JAVA_VERSION_BUILD 13
ENV JAVA_PACKAGE server-jre
# Copy all checksums from local to the container
# To compute a new checksum in the future...
# - Log into busybox with "docker run -it ohmygoshjosh/busybox" (run this on localdev)
# - Download the new file
# - "sha256sum <new-file_name>"
# - Write the new checksum into the appropriately named file in deploy/checksums
# TIP: For Java, note that we compute the checksum on the .tar and NOT the .tar.gz file!
# TIP: Be sure to copy the entire output of "sha256sum", not just the SHA itself.
COPY deploy/checksums checksums
# Download and unarchive Java
RUN curl -kLOH "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie"\
http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz &&\
gunzip ${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz &&\
[ "$(cat /checksums/${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.sha256)" = "$(sha256sum ${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar)" ] &&\
tar -xf ${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar -C /opt &&\
rm ${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar &&\
ln -s /opt/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR} /opt/jdk &&\
rm -rf /opt/jdk/*src.zip \
/opt/jdk/lib/missioncontrol \
/opt/jdk/lib/visualvm \
/opt/jdk/lib/*javafx* \
/opt/jdk/jre/lib/plugin.jar \
/opt/jdk/jre/lib/ext/jfxrt.jar \
/opt/jdk/jre/bin/javaws \
/opt/jdk/jre/lib/javaws.jar \
/opt/jdk/jre/lib/desktop \
/opt/jdk/jre/plugin \
/opt/jdk/jre/lib/deploy* \
/opt/jdk/jre/lib/*javafx* \
/opt/jdk/jre/lib/*jfx* \
/opt/jdk/jre/lib/amd64/libdecora_sse.so \
/opt/jdk/jre/lib/amd64/libprism_*.so \
/opt/jdk/jre/lib/amd64/libfxplugins.so \
/opt/jdk/jre/lib/amd64/libglass.so \
/opt/jdk/jre/lib/amd64/libgstreamer-lite.so \
/opt/jdk/jre/lib/amd64/libjavafx*.so \
/opt/jdk/jre/lib/amd64/libjfx*.so
# Set environment vars
ENV JAVA_HOME /opt/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
# INSTALL TYPESAFE ACTIVATOR AND GENERATE THE SERVICE'S BIN FILE
# ------------------------------------------------------------------------------
# Typesafe Activator Version
ENV ACTIVATOR_VERSION 1.2.12
# Copy all our microservice's source code into the container
COPY api/ /app/
# Add the "tinysteps" group and user
RUN adduser -D -H tinysteps tinysteps
# The activator file is ~350MB. When dealing with Docker locally, it's preferable to uncomment this line
# Note that you'll also need to comment out the "wget http://downloads.typesafe..." line from the RUN command
# COPY deploy/downloads/ /opt
# Set the working directory
WORKDIR /opt
# Download the full version of Typesafe Activator (contains all Play Framework libraries)
RUN wget http://downloads.typesafe.com/typesafe-activator/${ACTIVATOR_VERSION}/typesafe-activator-${ACTIVATOR_VERSION}.zip &&\
[ "$(cat /checksums/typesafe-activator-${ACTIVATOR_VERSION}.zip.sha256)" = "$(sha256sum typesafe-activator-${ACTIVATOR_VERSION}.zip)" ] &&\
unzip -o typesafe-activator-${ACTIVATOR_VERSION}.zip &&\
chown tinysteps:tinysteps /opt/activator-${ACTIVATOR_VERSION} &&\
# Create the binary executable that runs our service and delete unneeded files
cd /app &&\
/opt/activator-${ACTIVATOR_VERSION}/activator dist &&\
cd /app/target/universal &&\
unzip /app/target/universal/${MICROSERVICE_NAME}-1.0-SNAPSHOT.zip &&\
mv /app/target/universal /app-run &&\
chown -R tinysteps:tinysteps /app-run &&\
# Clean up all our files
rm -Rf /app &&\
rm /opt/typesafe-activator-${ACTIVATOR_VERSION}.zip &&\
rm -Rf /opt/activator-${ACTIVATOR_VERSION} &&\
rm -Rf /root/.ivy2
# Tell Docker that port 9001 should be exposed from this container
EXPOSE 9001
# The container's job in life is to run this command
CMD /app-run/${MICROSERVICE_NAME}-1.0-SNAPSHOT/bin/${MICROSERVICE_NAME} -Dhttp.port=9001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment