Unable to expose Docker Container

I tried running a Docker container that ran a flask application. It works when I do

curl 0.0.0.0:50000

Since I get a response of the webpage. However, I'm unable to access it through my domain.

Currently on Traefik
v2.1.2

My docker-compose file is similar to the following:

version: "3"

networks:
  proxy:
    external: true
  internal:
    external: false
services:

  hog:
    # The official v2.0 Traefik docker image
    image: traefik:v2.1.2
    # Enables the web UI and tells Traefik to listen to docker
    command:
      - --entrypoints.web.address=:80
      - --providers.docker
      - --api
      - --ping=true
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - proxy
    labels:
      - "traefik.http.routers.api.rule=Host(`subdomain.domain.tld`)"
      - "traefik.http.routers.api.service=api@internal"
      - "traefik.http.routers.api.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=admin:password"

  some-container:
    image: username/some-container:latest
    restart: always
    labels:
      - traefik.http.routers.some-container.rule=Host(`subdomain.domain.tld`)
      - traefik.http.services.some-container.loadbalancer.server.port=50000
    networks:
      - proxy
      - internal

It shows up in the dashboard fine, but I'm thinking that because I didn't specify the entrypoint may be the problem. But interestingly, when I run the following (in the same docker-compose file):

  ghost:
    image: ghost:latest
    restart: always
    ports:
      - 2367-2368:2368
    environment:
      url: http://subdomain.domain.tld
      database__client: sqlite3
    networks:
      - proxy
    labels:
      - traefik.http.routers.ghost.rule=Host(`subdomain.domain.tld`)
    volumes:
      - some volume
    deploy:

It works perfectly. I'm thinking that maybe because I have around 20 services using the same entrypoint, this may cause the problem? Not completely sure. Will update if I fix this problem.

Hello,

you can put a lot more routers than that on an entry point, so It's clearly not the problem.

As you have only one entry point you don't need to specify it.

on some-container I can see 3 possible problems:

  • you are using multiple networks https://docs.traefik.io/v2.1/routing/providers/docker/#traefikdockernetwork
  • you are using the same rule everywhere Host(`subdomain.domain.tld`) (I know that you have obfuscated the domains, but with your sample I can't say if it's related to that or not)
  • maybe the port set by traefik.http.services.some-container.loadbalancer.server.port=50000 is wrong

Updated my docker compose file:

  some-container:
    image: name/some-container
    restart: always
    expose:
      - 4999
    ports:
      - 4999:4999
    labels:
      - traefik.http.routers.some-container.rule=Host(`run.domain.dev`)
      - traefik.http.services.some-container.loadbalancer.server.port=4999
    networks:
      - proxy

So I basically stripped it down and it does work! but The weird thing is that when I use my domain.dev domain instead of domain.io domain, it doesn't work.

This is really puzzling as I have the same exact A records (basically the run subdomain is pointed to IP address 1.2.3.4 for both domain.dev and domain.io) on both domain.dev and domain.io, but the domain.dev doesn't work (doesn't even connect).

I'll see if I can investigate, but could this be a potential Traefik issue? I really can't see how this isn't.

It's not a Traefik issue, it's a configuration issue.

FYI you don't need to use expose and ports.

Yeah I know. Just did it make it work. Will fix configs later.

I'll try again and figure out why I'm getting this, but thanks! I think my initial config would've worked if I used my .io domain and I'll test that out now.