Enter your keyword

The DevOps Show EP1

The DevOps Show EP1

The DevOps Show EP1

We started the DevOps show at the Digital Factory in Mauritius. The idea is to share knowledge about DevOps and related technologies such as Docker, Kubernetes, OpenShift and Azure DevOps.

In the second meetup of the series, Renghen and Myself talked about Docker Compose. Here’s a summary of the discussion:

Introduction

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Compose works in all environments: production, staging, development, testing, as well as CI workflows.

Using Compose is basically a three-step process:

  1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
  2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  3. Run docker-compose up and Compose starts and runs your entire app.

 

Scenario

We shall run 2 containers, the first one having a Java Application and the Second one an Angular Application consuming APIs from the Java App.

 

Angular App

The docker file for the Angular App is straighrforward, copy the items from the build to the Alpine image.

FROM nginx:alpine

WORKDIR /usr/share/nginx/html
COPY dist/ .

Java App

The Docker file for the Java Api also copies the Jar file to the Alpine image

FROM java:openjdk-8-jdk-alpine

# add directly the jar
ADD target/*.jar /app.jar

# to create a modification date
RUN sh -c 'touch /app.jar'

CMD ["java", "-jar", "/app.jar", "--spring.profiles.active=prod"]

EXPOSE 8080

Compose File

The compose file will be as follows

  • build: build it from the Dockerfile in the parent directory
  • ports: map the external port to the internal port

The containers can be started or stopped using the commands below:

sudo docker-compose up -d
sudo docker-compose down

 

Note: The write-up for version 3 of compose is in progress and this article will be updated soon.

 

Happy coding!

Chervine