-
Notifications
You must be signed in to change notification settings - Fork 36
/
docker-compose.yml
59 lines (51 loc) · 2.44 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
# A docker-compose must always start by the version tag.
# We use "3" because it's the last version at this time.
version: "3"
# You should know that docker-composes works with services.
# 1 service = 1 container.
# For example, a service maybe, a server, a client, a database...
# We use the keyword 'services' to start to create services.
services:
# As we said at the beginning, we want to create: a server and a client.
# That is two services.
# First service (container): the server.
# Here you are free to choose the keyword.
# It will allow you to define what the service corresponds to.
# We use the keyword 'server' for the server.
server:
# The keyword "build" will allow you to define
# the path to the Dockerfile to use to create the image
# that will allow you to execute the service.
# Here 'server/' corresponds to the path to the server folder
# that contains the Dockerfile to use.
build: server/
# The command to execute once the image is created.
# The following command will execute "python ./server.py".
command: python ./server.py
# Remember that we defined in'server/server.py' 1234 as port.
# If we want to access the server from our computer (outside the container),
# we must share the content port with our computer's port.
# To do this, the keyword 'ports' will help us.
# Its syntax is as follows: [port we want on our machine]:[port we want to retrieve in the container]
# In our case, we want to use port 1234 on our machine and
# retrieve port 1234 from the container (because it is on this port that
# we broadcast the server).
ports:
- 1234:1234
# Second service (container): the client.
# We use the keyword 'client' for the server.
client:
# Here 'client/ corresponds to the path to the client folder
# that contains the Dockerfile to use.
build: client/
# The command to execute once the image is created.
# The following command will execute "python ./client.py".
command: python ./client.py
# The keyword 'network_mode' is used to define the network type.
# Here we define that the container can access to the 'localhost' of the computer.
network_mode: host
# The keyword'depends_on' allows you to define whether the service
# should wait until other services are ready before launching.
# Here, we want the 'client' service to wait until the 'server' service is ready.
depends_on:
- server