-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocker-compose.yaml
75 lines (68 loc) · 4.49 KB
/
docker-compose.yaml
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
73
74
75
version: "3.8" # notice we put a dash in front of things that are listed that are single valued unlike environment variables are key value pairs and didnt need a dash (-)
services: # these services run in --rm mode always by default , it runs in attach mode by default
mongodb: # mongodb service container
image: 'mongo' # we specify the image to use , it will be looked up locally and in Docker Hub Repository
container_name: 'mongodb' # name of the container
ports:
- "27017:27017"
volumes:
- data:/data/db # mount a volume on the container, the volume will be created if it doesn't exist
#environment:
# MONGO_INITDB_ROOT_USERNAME:root # colon creates a yaml object and dont needs a dash
# MONGO_INITDB_ROOT_PASSWORD:root
# - MONGO_INITDB_DATABASE=test # = needs a dash
env_file:
- './env/mongo.env' # load environment variables from a file
# restart: always # restart the container if it dies
networks: # you dont need to define a network because docker compose automatically creates a network for you a new environment for all the services specified in this compose file and it will add all the services to that network
- goals-net # now mongodb is added to the default network && goals-net network too
backend: # backend service container
build: # build the image from the Dockerfile in the current directory
context: ../server # the path of the directory that contains dockerfile
dockerfile: Dockerfile # the Dockerfile to use
# tag: backend # tag the image as backend
image: goals-backend:v1 # we specify the image to use , it will be looked up locally and in Docker Hub Repository
container_name: 'backend' # name of the container
ports: # ports to expose on the container
- "3000:3000"
volumes:
- logs:/app/logs # mount a volume on the container, the volume will be created if it doesn't exist
- ./backend:/app # mount the relative directory as a bind mount
- /app/node_modules # mount the absolute directory as a bind mount
env_file:
- './env/backend.env' # load environment variables from a file
# restart: always
depends_on: # this service depends on the mongodb service to be up and running already
- mongodb
networks: # you dont need to define a network because docker compose automatically creates a network for you a new environment for all the services specified in this compose file and it will add all the services to that network
- goals-net # now backend is added to the default network && goals-net network too
frontend: # frontend service container
build: # build the image from the Dockerfile in the current directory
context: ../client # the path of the directory that contains dockerfile
dockerfile: Dockerfile # the Dockerfile to use
# tag: frontend # tag the image as frontend
image: goals-frontend:v1 # we specify the image to use , it will be looked up locally and in Docker Hub Repository
container_name: 'frontend' # name of the container
ports: # ports to expose on the container
- "8000:8000"
volumes:
- ./frontend/src:/app/src # mount the relative directory as a bind mount
- /app/node_modules # mount the absolute directory as a bind mount
stdin_open: true # -i allow the container to be able to be open for input
tty: true # -t allow the container to be able to be attached to via the terminal
depends_on: # this service depends on the backend service to be up and running already
- backend
networks: # you dont need to define a network because docker compose automatically creates a network for you a new environment for all the services specified in this compose file and it will add all the services to that network
- goals-net # now frontend is added to the default network && goals-net network too
volumes: # you have to define all the used name volumes in the compose file
data:
logs:
networks:
goals-net: # name of the network
# if you then use the same volume name in different services the volume will be shared so different containers can use same volume
# docker-compose up # this will create the containers and start them
# docker-compose down # this will stop the containers and remove them
# docker-compose rm # this will remove the containers but not the volumes
# docker-compose ps # this will show the status of the containers
# docker-compose logs # this will show the logs of the containers
# docker-compose exec # this will run a command in the container