You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This defines the configuration options, including the context and dockerfile,
6
+
# that will be applied when Compose builds the application image.
7
+
build:
8
+
# This defines the build context for the image build — in this case, the current project directory.
9
+
context: .
10
+
# This specifies the Dockerfile in your current project directory as the file
11
+
dockerfile: Dockerfile
12
+
image: app
13
+
container_name: app
14
+
# This defines the restart policy. The default is no,
15
+
# but we have set the container to restart unless it is stopped.
16
+
restart: unless-stopped
17
+
env_file: .env
18
+
ports:
19
+
# This maps port from .env on the host to same port number on the container.
20
+
- "3000:$PORT"
21
+
links:
22
+
- mongo
23
+
volumes:
24
+
# This is a bind mount that mounts our application code on the host to the /home/node/app directory on the container.
25
+
# Any changes you make to your host code will be populated immediately in the container.
26
+
- ./:/home/node/app
27
+
28
+
29
+
mongo:
30
+
# To create this service, Compose will pull the mongo
31
+
image: mongo:latest
32
+
container_name: mongo
33
+
restart: unless-stopped
34
+
# This tells Compose that we would like to add environment variables
35
+
# from a file called .env, located in our build context.
36
+
env_file: .env
37
+
environment:
38
+
# MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD together create
39
+
# a root user in the admin authentication database and ensure that authentication is enabled
40
+
# when the container starts. We have set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
41
+
# using the values from our .env file, which we pass to the db service using the env_file option.
42
+
- MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN
43
+
- MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PWD
44
+
ports:
45
+
- "27017:27017"
46
+
volumes:
47
+
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
48
+
# This will ensure that you don’t lose data in cases where you stop or remove containers.
49
+
- dbdata:/data/db
50
+
51
+
# Our top-level volumes key defines the volumes dbdata.
52
+
# When Docker creates volumes, the contents of the volume are stored in a part of the host filesystem, /var/lib/docker/volumes/, that’s managed by Docker.
53
+
# The contents of each volume are stored in a directory under /var/lib/docker/volumes/ and get mounted to any container that uses the volume.
54
+
# In this way, the data that our users will create will persist in the dbdata volume even if we remove and recreate the db container.
0 commit comments