Hello to all the readers!
I have setup multi container applications separate using docker run commands. But docker offers a nice way to setup multi container apps using Docker compose.
Here we define each service in a docker-compose.yml file and then a single command spins up everything for us.
The docker-compose.yml for mysql and app containers.
services:
  app:
    image: node:18-alpine
    command: sh -c "yarn install && yarn run dev"
    ports:
      - 127.0.0.1:3000:3000
    working_dir: /app
    volumes:
      - ./:/app
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: todos
  mysql:
    image: mysql:8.0
    volumes:
      - todo-mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos
volumes:
  todo-mysql-data:Then run
docker compose up -d
docker compose logs -fThis will create volume, runs app and mysql containers and networks. This helps to define the entire application stack.
In order to bring the entire application stack down, we will run
docker compose down