-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
22 lines (21 loc) · 1.27 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
version: '3'
services:
mongo:
image: mongo
# volumes:
# - ./db:/data/db # uncomment this line for database persistency
ports:
- "27017:27017"
server:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "4000:4000"
volumes:
- /app/node_modules
- .:/app
depends_on:
- mongo
# In our docker-compose.yml we have added 'database' as a name to our MongoDB service. Now, we can use this as a reference while connecting to MongoDB. So in our index.js we can change mongoose.connect('localhost:27017/myapp') to mongoose.connect('database:27017/myapp')
# Volumes allow you to mount folders on the host machine to folders in the container. Meaning, when something inside the container refers to a folder, it will actually be accessing a folder on the host machine. This is especially helpful for database containers because containers are meant to be disposable. With a mount to the physical folder on the host machine, you’ll be able to destroy a container and rebuild it and the data files for the container will still be there on the host machine. So add a volume tag in the db section mounting the /data/db folder in the container (where Mongo stores its data) to the db folder in your application’s root folder