I'm trying to get a Hello World up and running but failing miserably.
I started with the basic example Traefik gives with the whoami image, which works, but as soon as I apply the same config to a custom image I have with a server running, I get an error: time="2020-02-14T19:30:57Z" level=error msg="port is missing" providerName=docker container=my_custom_image-src-2812cdd4df598b75a9cb03395e72398370ca9e27a9abf531d5f813ee524b42a7
Here is my docker-compose:
version: '3.4'
services:
traefik:
# The official v2.0 Traefik docker image
image: traefik:v2.0
# Enables the web UI and tells Traefik to listen to docker
command: --api.insecure=true --providers.docker
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
whoami:
# A container that exposes an API to show its IP address
image: containous/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.whatever.localhost`)"
my_custom_image:
container_name: my_custom_image
image: my_custom_image
build:
context: ./my_custom_image
labels:
- "traefik.http.routers.my_custom_image.rule=Host(`my_custom_image.whatever.localhost`)"
I did. Inside my container I have a server listening on 120.0.0.1:8080, and I set "traefik.http.services.my_custom_image.loadbalancer.server.port=8080". Is that correct?
Just in case anyone runs into this specific scenario:
Also make sure that your container exposes the/a port and if needed set the Traefik port in the labels. (I.e. if there are multiple ports exposed or a non-default port is being used, overriding the Traefik port for the container might be necessary.)
If there image does not expose a particular port by default, you can solve it this way: