Skip to content

Instantly share code, notes, and snippets.

@richchurcher
Last active August 3, 2020 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richchurcher/adc6b41b08d44222f57edd3417c92bd7 to your computer and use it in GitHub Desktop.
Save richchurcher/adc6b41b08d44222f57edd3417c92bd7 to your computer and use it in GitHub Desktop.
docker-compose extension field syntax
version: "3"
# See: https://hackernoon.com/a-better-way-to-develop-node-js-with-docker-cd29d3a0093
# This is the v3 syntax to achieve essentially the same thing. Note that if you launched this with a simple
# `docker-compose up` it would attempt to start every definition at the service level, which is not what you
# want! However, you can leverage the fact that `depends_on` launches the listed services prior to the
# dependent service, so in this example `docker-compose up myproject_web` would start the db container
# before the web container. Alternatively, you could just throw the stuff you don't want started with `up`
# into a separate YAML file, as the article demonstrates.
services:
x-web-config:
&web-config
env_file:
- .env
- ./server/.env
environment:
NODE_ENV: development
image: node:12
volumes:
- .:/app
working_dir: /app
install:
<< : *web-config
command: ["yarn"]
myproject_web:
<< : *web-config
command: ["yarn", "start"]
container_name: myproject_web
depends_on:
- myproject_db
networks:
- myproject
ports:
- 3000:3000
- 3002:3002
restart: unless-stopped
stdin_open: true
myproject_db:
image: "postgres:11.5"
restart: always
container_name: myproject_db
ports:
- 5432:5432
volumes:
- ./data:/var/lib/postgresql/data
environment:
POSTGRES_DB: mydbname
networks:
myproject:
driver: bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment