Work with traefik
Traefik is a transport proxy that will take care of routing network traffic to the stack applications. We have it connected to docker socket listening to all the changes happening with containers.
To set up http traffic routing we just need to add a few labels to the service described in the stack and Traefik will do the rest.
Select web_hello_world stack and click on Editor tab at the top of the page. Then copy and paste this configuration to the editor and click Update the stack. Do not forget to substitute example.com with you domain name.
version: "2.4"
services:
test:
image: far4599/go-hello-world-http:latest
networks:
- traefik
labels:
traefik.enable: 'true'
# service
traefik.http.services.web_hello_world_svc.loadbalancer.server.port: '8080'
# https
traefik.http.routers.web_hello_world.rule: Host(`hello.example.com`)
traefik.http.routers.web_hello_world.entrypoints: websecure
traefik.http.routers.web_hello_world.service: web_hello_world_svc
traefik.http.routers.web_hello_world.tls.certresolver: myresolver
networks:
traefik:
external: true
Visit https://hello.example.com to see that everything works fine.
Let's look at the labels and figure out what they mean:
traefik.enable: 'true'notifies Traefik that this service is to be monitored by Traefik and the configuration in labels shall be applied.traefik.http.services.web_hello_world_svc.loadbalancer.server.port: '8080'creates a definition of a serviceweb_hello_world_svcwith a load balancer configuration to send all the traffic to the port8080of the container.traefik.http.routers.web_hello_world.rule: Host(``hello.example.com``)creates a definition of a routerweb_hello_worldand instructs Traefik to link the router with the domain name.traefik.http.routers.web_hello_world.entrypoints: websecuresays the router will be accessible only through SSL connection (https://).traefik.http.routers.web_hello_world.service: web_hello_world_svclinks the router toweb_hello_world_svcservice mentioned above.traefik.http.routers.web_hello_world.tls.certresolver: myresolverindicates that the router shall usemyresolverto get SSL certificate for the domain.
With this simple setup you get outstanding tools with lots of possibilities to boost web development or your personal use.