The Doppler Quarterly Spring 2018 | Page 58

Dockerfile: FROM openjdk:8 COPY target/demo-0.0.1-SNAPSHOT.jar /usr/src/demo-0.0.1- SNAPSHOT.jar CMD java -jar /usr/src/demo-0.0.1-SNAPSHOT.jar Now that we had a Dockerfile defined, we needed to build an image and give it a tag: $ docker image build —tag demo:v0.0.1 . Sending build context to Docker daemon 20.07MB Step 1/3 : FROM openjdk:8 —-> db77212ffe05  Step 2/3 : COPY target/demo-0.0.1-SNAPSHOT.jar /usr/src/ demo-0.0.1-SNAPSHOT.jar —-> Using cache —-> edff15005e12 Step 3/3 : CMD java -jar /usr/src/demo-0.0.1-SNAPSHOT.jar —-> Using cache —-> 5207b1f7b396 Successfully built 5207b1f7b396 Successfully tagged demo:v0.0.1 The preceding command looked for the Dockerfile in the current directory “.”, read the instructions in the Dockerfile and downloaded and compiled the image with a tag of “demo:v0.0.1” Now that we had an image built, we could run it. $ docker container run —detach —publish 8080:8080 demo:v0.0.1 We ran the container with the “—detach” option, so it runs in the background. Since the application listens for connections on port 8080, we needed to pub- lish that port to the host. In addition, we asked for the same tag that we just built: “demo:v0.0.1.” At this point, we were able to use a browser to get a response from “http://localhost:8080/.” Next Steps Once we built and tested the container locally, we needed to push it to a regis- try. We created an organization on Docker Hub and used a private repository to hold all of the application’s container versions. Next, we updated our CI/CD pipeline to trigger a build when a change is com- mitted. The pipeline does a compile on the application, runs a Docker build on the Dockerfile with a version tag and then pushes it to the Docker Hub repository. Now that we have a Docker image tagged with a version, deploying a new release is simply an update to the container cluster to roll out a newer version of the container. We chose the AWS Elastic Container Service (ECS), since we wanted a managed service to reduce the time spent on operational tasks. 56 | THE DOPPLER | SPRING 2018