-
-
Notifications
You must be signed in to change notification settings - Fork 490
/
docker-compose.yml
72 lines (68 loc) · 2.95 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# version: '2.4'
# versions no longer needed for compose CLI use (as of 2020)
# If using swarm, you'll still need version 3.9
services:
node:
build:
context: .
args:
- NODE_ENV=development
# you can use legacy debug config or new inspect
# NOTE: if nodemon isn't restarting on changes, you might be on Windows
# which has trouble seeing file changes, so add -L to use legacy polling
# https://github.com/remy/nodemon#application-isnt-restarting
#command: ../node_modules/.bin/nodemon --debug=0.0.0.0:5858
command: ../node_modules/.bin/nodemon --inspect=0.0.0.0:9229 ./bin/www
ports:
- "80:3000"
- "9229:9229"
- "9230:9230"
volumes:
- .:/opt/node_app/app
# bind-mounting these two files in will let you add packages during development without rebuilding
# for example, to add bower to your app while developing, just install it inside the container
# and then nodemon will restart. Your changes will last until you "docker compose down" and will
# be saved on host for next build.
# remember to isntall from the parent directory to the code bind-mount:
# docker compose exec -w /opt/node_app node npm install --save bower
- ./package.json:/opt/node_app/package.json
- ./package-lock.json:/opt/node_app/package-lock.json
# this is a workaround to prevent host node_modules from accidently getting mounted in container
# in case you want to use node/npm both outside container for test/lint etc. and also inside container
# this will overwrite the default node_modules dir in container so it won't conflict with our
# /opt/node_app/node_modules location. Thanks to PR from @brnluiz
- notused:/opt/node_app/app/node_modules
environment:
- NODE_ENV=development
- MONGO_USERNAME=root
- MONGO_PASSWORD=example
- MONGO_HOSTNAME=mongo
- MONGO_PORT=27017
- MONGO_DATABASE_NAME=example-database
depends_on:
mongo:
condition: service_healthy
healthcheck:
disable: true
mongo:
image: mongo:4
ports:
- "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=example
- MONGO_INITDB_DATABASE=example-database
volumes:
# this is an example of how to seed data in mongo containers. The Docker Hub mongo README
# explains that any data dropped into the docker-entrypoint-initdb.d directory will be injected
# into mongo at startup. This is also a common pattern for other db solutions like mysql or psql
- ./database/seed.js:/docker-entrypoint-initdb.d/seed.js
# we need to check health here, so that docker compose will wait for a healthy mongo before it starts node
healthcheck:
test: "[ `echo 'db.runCommand(\"ping\").ok' | mongo localhost/example-database --quiet` ] && echo 0 || echo 1"
interval: 5s
start_period: 10s
timeout: 4s
retries: 3
volumes:
notused: