Objective

Make a docker image of our first microservice – the catalog-service. Create a Dockerfile, and build a docker image out of it.

Technologies introduced

  1. Docker
  2. Dockerfile

Create a Dockerfile describing the image

What does your Dockerfile contain? See the complete Dockerfile.

  • Which is the base image for this container? What do we need for our application to run?
    1. An operating system
    2. A JRE

The base image I have chosen here is openjdk:8u92-jre-alpine, which is an open JDK installed on an alpine LINUX system. Alpine linux is a small, efficient LINUX distribution.

FROM openjdk:8u92-jre-alpine
  • Work Directory
WORKDIR /catalog-service

Within the container, the application will run from this folder

  • Version of app as argument
ARG version

This is not absolutely essential, but here we are taking the “version” of catalog-service as an argument to the Dockerfile, so that we can choose to use any version to build the image

  • Adding the catalog-service JAR file to the image
ADD ./build/libs/catalog-service-${version:-1.0.0.RELEASE}.jar /catalog-service/catalog-service.jar

We are copying the specified version (1.0.0.RELEASE, if no version argument provided) of catalog-service from our build directory into the work directory /catalog-service

  • What command should be run when the container starts?
CMD java -jar catalog-service.jar

We ask docker to run the java command and execute the Main class from the catalog-service JAR.

Build an image from the Dockerfile

Change directory into the folder that contains the Dockerfile, and do a docker build.

cd catalog-service
docker build --tag=catalog-service .

Here we name the image as “catalog-service” using the –tag argument.

Verify that the image was created

List the docker images in your machine and verify that catalog-service is listed there:

docker images

Source code

Tag “step3” in repository “catalog-service

git clone https://github.com/microxs-demo/catalog-service
cd catalog-service
git checkout tags/step3

Video

Step 3 video

 

 

Advertisements