Linux Containers

⏱ 2 mins remaining

Docker Compose

Docker Compose

Here is an example of a docker compose file

version: '3'

services:
  webapp:
    image: nginx:latest
    ports:
      - "8080:80"
    volumes:
      - web_data:/usr/share/nginx/html
    environment:
      - NGINX_VERSION=latest
    networks:
      - frontend
      - backend
    depends_on:
      - api

  api:
    build:
      context: ./api
      dockerfile: Dockerfile
    command: npm start
    volumes:
      - api_config:/etc/api/
    environment:
      - NODE_ENV=production
    networks:
      - backend

  database:
    image: postgres:latest
    environment:
      - POSTGRES_DB=mydatabase
      - POSTGRES_USER=myuser
      - POSTGRES_PASSWORD=mypassword
    networks:
      - backend

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge

volumes:
  web_data:
  api_code: