Brook Preloader

Blog

Running related containers together – Docker Compose

In our last 2 blogs we executed both, a Dockerized B/E App and FE Application in isolated mode. In real scenario multiple applications work together and have dependency on each other, especially in n-tier & microservices architectures.

In this blog we’ll create a docker compose file to run both the dockers together. UI app will be powered with the APIs exposed in B/E docker.

Pre-requisites:

  1. Pre-requisites from previous 2 blogs
  2. UI and B/E dockerized applications from previous 2 blogs
  3. docker-compose installed, this is usually pre-installed if docker desktop is installed

First, we’ll update the angular app to get & update count values in B/E. We need to angular service that interacts with backend API. The change looks like –

CORS has to be enabled in B/E application so that it can accept requests from angular application. The change looks like

Finally, we need to create a docker-compose yaml file that configures and runs both the docker containers in expected order. Contents of docker compose yaml are –

The above docker compose defines 2 services

  1. counterbe : B/E service using demo/samplespringboot as image and maps host 8099 port to container 8099 port
  2. counterfe: F/E service using demo/counterappui as image and maps hots 4201 port to container 4201 port. Also, depends_on specifies that counterfe service depends on the counterbe container.

Bringing docker compose up: Use the below command to start the instances from docker compose file

docker-compose -f docker-compose-counter.yaml up -d‘

The above command runs the container in detached mode. Use the ‘docker ps’ command to check if the dockers are up and running.

To verify if app is up and running, access “http://localhost:4201/counter/” URL in browser and check if below UI comes up

Stopping the containers: Run the below command to stop running containers

docker-compose -f docker-compose-counter.yaml down’

This article just scratches the surface of docker-compose, it is very useful in enterprise applications or product solutions. The complete documentation of docker compose can be found at https://docs.docker.com/compose/

The next articles/blogs would address the container orchestration and related concepts – Kubernetes basics, hands-on with Kubernetes configuration on minikube.

0 0 vote
Rating
guest
0 Comments
Inline Feedbacks
View all comments