May 18, 2022

Docker HelloWorld_2

Continue from the hello_world_1, here comes another notes on running multiple containers with docker compose.

With Docker compose, we can configure and start multiple containers with a single yaml file. This is helpful for a technology stack with multiple technologies.

As an example, say that you are working on a project that uses a MySQL database, Python for AI/ML, NodeJS for real-time processing, and .NET for serving API’s. Docker makes this easier with the help of compose.

docker compose is a yaml file in which we can configure different types of services. Then with a single command all containers will be built and fired up.

There are 3 main steps involved in using compose:    

  • Generate a Dockerfile for each project.    
  • Setup services in the docker-compose.yml file.    
  • Fire up the containers.

Here is the full copy of docker-compose.yml.

docker-compose.yml:

version: '3.4'
services:
  super-app-db:
    image: mysql:8.0.28
    environment:
      MYSQL_DATABASE: 'super-app'
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - '3306:3306'
    expose:
      - '3306'
  super-app-node:
    build: ./node
    ports:
      - "3000:3000"
  super-app-dotnet:
    build: ./dotnet
    ports:
    - "8080:80"
  super-app-python:
    build: ./python
  super-app-php:
    build: ./php
    ports:
    - "8000:80"

Then, we need to:

  • Configure MySQL
  • Configure NodeJS
  • Configure .NET 
  • Configure Python
  • Configure PHP

 

Links: