Skip to content

Instantly share code, notes, and snippets.

@an01f01
Created November 2, 2023 18:01
Show Gist options
  • Save an01f01/efe26ec9949e4354eb4f4e44151b7d92 to your computer and use it in GitHub Desktop.
Save an01f01/efe26ec9949e4354eb4f4e44151b7d92 to your computer and use it in GitHub Desktop.
# 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 ./app.py".
command: python /server/app.py
# Remember that we defined in'server/app.py' 8000 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 8000 on our machine and
# retrieve port 8000 from the container (because it is on this port that
# we broadcast the server).
ports:
- 8000:8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment