Step 6: Containerize Application
Docker can build images automatically by reading the instructions from a Dockerfile, a text file that
contains all the commands, in order, needed to build a given image. Dockerfiles adhere to a specific
format and use a specific set of instructions. We can learn the basics on the Dockerfile Reference
page.
Docker has a simple Dockerfile file format that it uses to specify the "layers" of an image. So let’s go
ahead and create a Dockerfile in our Spring Cassandra Example Project:
Dockerfile
FROM java:8
# Install maven
RUN apt‐get update
RUN apt‐get install ‐y maven
WORKDIR /code
# Prepare by downloading dependencies
ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
# Adding source to WORKDIR
ADD src /code/src
RUN ["mvn", "package"]
EXPOSE 8080
CMD ["java", "‐jar", "target/demo‐0.0.1‐SNAPSHOT.jar"]
Copyright and all intellectual property belongs to Brockhaus Group 23