Getting mad on Docker networking

i really have no clue anymore, i tried almost every combination i could imagine but in the end was not able to find a solution that fits. Have have a dockerized app that depends on elasticsearch, redis, traefik and postgres

but for some reason the networking communication between traefik and my actuall app seems to be somehow broken. I simply want that im able to reach my app at 127.0.0.1:80 but traefik alsways returns 404 not found

version: '3'

networks:
  backend-app:
    internal: true
  frontend-app:
    internal: false

volumes:
  esdata:
    driver: local
  postgresdata:
    driver: local

services:
  app-proxy:
    container_name: app-proxy
    image: traefik  # The official Traefik docker image
    command: --api --docker  # Enables the web UI and tells Traefik to listen to docker
    ports:
      - 80:80      # The HTTP port
      - 8080:8080  # The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock  # So that Traefik can listen to the Docker events
    depends_on:
      - myproject
    networks:
      - frontend-app
      - backend-app

  redis:
    image: redis:alpine
    container_name: app-redis
    networks:
      - backend-app
    ports:
      - 6379
    labels:
      - traefik.enable=false

  postgres:
    image: postgres:latest
    container_name: app-postgres
    networks:
      - backend-app
    ports:
      - 5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mysupersecretpass
      POSTGRES_DB: myproject
    volumes:
      - postgresdata:/var/lib/postgresql/data
    labels:
      - traefik.enable=false

  elasticsearch:
    image: elasticsearch:6.5.3
    container_name: app-elasticsearch
    environment:
      - cluster.name=app-cluster
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms2048m -Xmx2048m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata:/usr/share/elasticsearch/data
    ports:
      - 9200
    networks:
      - backend-app
    labels:
      - traefik.enable=false

  myproject:
    build: .
    command: bash -c "python manage.py makemigrations myproject myproject_Accounts && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    container_name: app
    volumes:
      - .:/myproject
    labels:
      - traefik.backend=app
      - traefik.enable=true
      - traefik.passHostHeader=true
      - traefik.frontend.rule=Host:app
      - traefik.docker.network=frontend-app
      - traefik.port=8000
    networks:
      - backend-app
    depends_on:
      - postgres
      - elasticsearch
      - redis
    ports:
      - 8000

How would you get this done if you want that the proxy routet app is the only accessible entrypoint for the deployment at http://127.0.0.1:80 and have elasticsearch, redis, postgres routed internal

many thanks in advance

Hi.

I’m having trouble understanding what you are trying to do, it’s not clear to me.

I think that you want to be able to point a web browser to the Docker Host using Port 80 or 8080 which the app-proxy service is listening on. You don’t show what hostname or service name that the app-proxy service is using to connect to your “Application” which I think is the myproject service. You need to provide more details here in order for us try and figure out what the problem is.

I think if your app-proxy service uses the name of your “Applications” service which is myproject it should be able to connect to it.

This registers the hostname ‘app’ for reverse proxying to the myproject service:

traefik.frontend.rule=Host:app

This network is missing in your network declaration on the myproject service:

traefik.docker.network=frontend-app

I am not aware if traefik is able to reverse proxy to containers when callen by ip (tbh, never seen someone trying).

Add the frontend-app network to your network list on the myproject service. Remove the backend-app network from the app-proxy service.

Finaly, modify the hosts file on your client to resolve the hostname ‘app’ to your docker hosts ip and try to access your application in the browser using the url http://app.