It is important to keep a good and simple folder structure, because the docker compose file in the root will be configured to look for Docker files using relative paths.
This way the docker-compose.yml file is the single entry point for all services in this server.
Within these folders for each service you can put anything, Node js, python, what ever you feeling that day.
name the folders the exact name you want the subdomain to be, so if you are building an API, call the folder api. This will result in a domain of api.company.com
I have called my examples servicea and serviceb for clarity sake.
user lower-case names,
keep names short and sweet, because the names will be the same as the sub domain you will create.
I will show you the entire compose file after we first understand how easy it is setup a service.
Here is a snippet to define a service:
Lets break it down line by line
services:
declare a services block
home:
declare a service by its give name, I called it home which corresponds to the folder name I created earlier.
container_name:
tells docker what to call the container.
build:
define a build label and sets the docker build context.
context:
defines the location of the project (relative path to the home directory)
dockerfile:
tells docker to load up the Dockerfile found in that directory.
labels:
This is where Traefik and docker meet for the first time.
"traefik.enable=true": enables Traefik
"traefik.http.routers.home.rule=Host(www.company.com)": sets the domain name using the Host() function which takes string as an argument. we have set it to www.company.com.
"traefik.http.routers.home.entrypoints=websecure": sets the app entry point to use websecure which we created in Part 1.
"traefik.http.routers.home.tls.certresolver=myresolver": sets the TLS Certificate Resolver to use the resolver defined by myresolver
Viola! that is it that is all that is needed to help Traefik autodiscover, start and manage your container. Creating a service is literally createing its resource in a folder with it's required Dockerfile and configureing it's service block in the main docker-compose.yml file in the root.