Docker run working - docker-compose not

I finally got my setup working, since I found the error. I just don't know how to fix it :frowning:

If I deploy my Traefik container like this

docker run -d --restart unless-stopped --name traefik -p 8080:8080 -p 80:80 -p 443:443 -v /mnt/Data/AppData/traefik/traefik.yml:/etc/traefik/traefik.yml -v /var/run/docker.sock:/var/run/docker.sock traefik:v2.3

It works without any problems.

If I'm doing the same in docker-compose, I get a timeout.

docker-compose.yml

version: '3'

services:
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.3
# Enables the web UI and tells Traefik to listen to docker
command: --api.insecure=true --providers.docker
ports:
# The HTTP port
- "80:80"
#The HTTPS port
- "443:443"
# 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
- /mnt/Data/AppData/traefik:/etc/traefik

The config file is the same, and everything in the dashboard, looks fine.

I can't figure this out. Anybody who can see the error and help ?
Thanks

/Robert

Hello @rhjensen79,

Maybe the problem is that you are trying to configure Traefik by using command flags and a configuration file at the same time and the resulting configuration is not the one you are expecting. As explained in the documentation the three configuration mechanisms are mutually exclusive.

If you are using a file, I would remove the command configuration in your docker-compose.yml and adds the API and Docker provider configurations in this file.

Hope this helps.

Thanks. That was a good suggestion, and I was not aware, of the "only one option".
But that did not work. It's still the same.

I get "Gateway timeout" no matter what I do, when running from docker-compose.
The only think working, is the management interface.

Can you provide the content of your static configuration and your logs?

For more detailed logs, maybe you can enable the debug log as described here.

Yes off course.

I cleaned all log files, and started the docker-compose, and did a connection, to one of the app's behind it.

Traefik.yml

traefik.yml

Docker configuration backend

providers:
docker:
defaultRule: "Host({{ trimPrefix / .Name }}.cmplab.dk)"

API and dashboard configuration

api:
insecure: true

entryPoints:
web:
address: ":80"

websecure:
address: ":443"

certificatesResolvers:
myresolver:
acme:
email: robert@robert-jensen.dk
storage: acme.json
httpChallenge:
# used during the challenge
entryPoint: web

Configuring a buffer of 100 lines

accessLog:
filePath: "/etc/traefik/access.log"
bufferingSize: 100

log:
filePath: "/etc/traefik/traefik.log"

Access.log

192.168.50.178 - - [27/Nov/2020:12:06:45 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 462 "-" "-" 1 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:06:47 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 2 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:06:50 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 3 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:06:52 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 4 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:06:55 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 5 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:06:57 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 6 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:00 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 7 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:02 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 8 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:05 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 9 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:07 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 10 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:10 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 12 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:12 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 13 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:15 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 14 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:17 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 15 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:20 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 16 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:22 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 17 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:25 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 18 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:27 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 19 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:30 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 20 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:32 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 21 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:35 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 22 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:37 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 23 "api@internal" "-" 0ms

80.62.116.205 - - [27/Nov/2020:12:07:10 +0000] "GET / HTTP/1.1" 504 15 "-" "-" 11 "devops@docker" "http://172.17.0.3:80" 30000ms

192.168.50.178 - - [27/Nov/2020:12:07:40 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 24 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:42 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 25 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:45 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 26 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:47 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 27 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:50 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 28 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:52 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 29 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:55 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 30 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:07:57 +0000] "GET /api/overview HTTP/1.1" 200 435 "-" "-" 31 "api@internal" "-" 0ms

192.168.50.178 - - [27/Nov/2020:12:08:00 +0000] "GET /api/http/routers?search=&status=&per_page=10&page=1 HTTP/1.1" 200 865 "-" "-" 32 "api@internal" "-" 0ms

Traefik.log

time="2020-11-27T12:06:44Z" level=error msg="service "ouroboros-ouroboros" error: port is missing" providerName=docker container=ouroboros-ouroboros-4f467920bacc37732f9bb397876d5adc7b9e4812e315e36da82fae415a2d3792

time="2020-11-27T12:08:01Z" level=error msg="accept tcp [::]:8080: use of closed network connection" entryPointName=traefik

time="2020-11-27T12:08:01Z" level=error msg="Error while starting server: http: Server closed" entryPointName=traefik

time="2020-11-27T12:08:01Z" level=error msg="Error while starting server: http: Server closed" entryPointName=traefik

time="2020-11-27T12:08:01Z" level=error msg="accept tcp [::]:80: use of closed network connection" entryPointName=web

time="2020-11-27T12:08:01Z" level=error msg="Error while starting server: http: Server closed" entryPointName=web

time="2020-11-27T12:08:01Z" level=error msg="accept tcp [::]:443: use of closed network connection" entryPointName=websecure

time="2020-11-27T12:08:01Z" level=error msg="Error while starting server: http: Server closed" entryPointName=web

time="2020-11-27T12:08:01Z" level=error msg="Error while starting server: http: Server closed" entryPointName=websecure

time="2020-11-27T12:08:01Z" level=error msg="Error while starting server: http: Server closed" entryPointName=websecure

time="2020-11-27T12:08:01Z" level=error msg="close tcp [::]:8080: use of closed network connection" entryPointName=traefik

time="2020-11-27T12:08:01Z" level=error msg="close tcp [::]:443: use of closed network connection" entryPointName=websecure

time="2020-11-27T12:08:01Z" level=error msg="close tcp [::]:80: use of closed network connection" entryPointName=web

Have you seen that there is an error for the ouroboros-ouroboros service?

Is it the service you are trying to call through Traefik?

Maybe the following documentation could help you: https://doc.traefik.io/traefik/providers/docker/#port-detection

Thanks the ourobros-service, is just a container, that updates other containers. So it has no need for ports. I did see that in the logs.

That does not explain why it does not work in docker-compose. It’s really strange imho

Normally, when Traefik replies with a Gateway timeout response it's because it cannot reach the service or the service does not respond in time.

Are you sure that Traefik can reach your service?
Maybe something is wrong with your docker networking?

Yes. But 2 things.

  1. The management interface is working.

  2. It’s working, when i do docker run, and not using compose.

So i have it working, just not with compose.

Does compose do something different with networks ?

I've made a quick test and I've reproduced your problem.

The problem is that Traefik is not in the same network of your service containers. That's because Docker compose creates a new network when Traefik is deployed.

To make it works, you will have to:

  1. Create a new docker network
  2. Deploy your services in the newly created network with the --network option
  3. Reference the newly created network in your compose file as explained here.
1 Like

Thank you so much.
It's now working, and best of all, I learned a lot, on how docker networks works.
I really appreciate it :slight_smile:

Thanks :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.