Docker Compose

docker-compose could be used to run multiple #202110201655 #202203281423 in a single Docker host using a YAML file. Name the following YAML file as docker-compose.yaml or later use the option -f to import the file:

version: 2
services:
  redis:
    image: redis
    networks:
      - back-end
  db:
    image: postdres:9.4
    networks:
      - back-end
  vote:
    build: ./vote
    ports:
      - 5000:80
    depends_on:
      - redis
    networks:
      - front-end
      - back-end
  result:
    build: ./result
    ports:
      - 5001:80
    depends_on:
      - db
    networks:
      - front-end
      - back-end
  worker:
    build: ./worker
    depends_on:
      - redis
      - db
    networks:
      - back-end

networks:
  front-end:
  back-end:

Run docker-compose up to bring up the set-up specified in the YAML file.

Since version 2, docker-compose can automatically set up a bridge network where all containers specified in the YAML file to be connected. Therefore, the option --link used in docker run is rendered as unnecessary. You could still establish dependencies between different containers with the option depends_on.

If the container need to be built from a local directory instead of a 202203251430, use the build option instead of image.

We could establish our own custom networks by using the networks option attached to the container. Make sure that those networks had been named at the top most level.

Links to this page
#container