# I need help setting up a custom api in a docker-compose

**URL:** <https://community.traefik.io/t/i-need-help-setting-up-a-custom-api-in-a-docker-compose/18575>\
**Category:** Traefik v2\
**Tags:** rest-api, docker\
**Created:** [May 9, 2023, 9:09pm UTC](https://community.traefik.io/t/i-need-help-setting-up-a-custom-api-in-a-docker-compose/18575 "2023-05-09T21:09:24Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![Max-Beier](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/max-beier/32/7104_2.png) [@Max-Beier](https://community.traefik.io/u/Max-Beier)\
**Post date:** [May 13, 2023, 6:12pm UTC](https://community.traefik.io/t/i-need-help-setting-up-a-custom-api-in-a-docker-compose/18575/21 "2023-05-13T18:12:20Z")

</div>

It's fixed. I putted the /api route on the root "/" and now it's working, it's weird. But thank you @bluepuma77 for all the potential solutions and the explanations.

Here is the final docker-compose.yml

```yml
version: '3.5'
services:
  traefik:
    image: traefik:v2.10.1
    restart: always
    ports:
      - 80:80
      - 443:443
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.docker.network=web
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --api.insecure=false
      - --certificatesresolvers.le.acme.email=${LETSENCRYPT_MAIL}
      - --certificatesresolvers.le.acme.storage=/etc/ssl/certs/acme.json
      - --certificatesresolvers.le.acme.tlschallenge=true
      - --log.level=DEBUG
      - --log.filePath=/etc/traefik/traefik.log
      - --log.format=json
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /etc/ssl/certs:/etc/ssl/certs
      - /etc/traefik:/etc/traefik
    networks:
      - web

  detactive_api:
    build: api
    restart: always
    env_file: .env
    ports:
      - 3000:3000
    labels:
      - traefik.enable=true
      - traefik.docker.network=web
      - traefik.http.routers.detactive_api.rule=Host(`${DOMAIN_NAME}`)
      - traefik.http.services.detactive_api.loadbalancer.server.port=3000
      - traefik.http.routers.detactive_api.tls.certresolver=le
      - traefik.http.routers.detactive_api.entrypoints=websecure
    depends_on:
      - db
    networks:
      - web
      - internal

  db:
    image: postgres
    restart: always
    env_file: .env
    ports:
      - 5432:5432
    volumes:
      - ./api/db/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - internal

  pgadmin:
    image: dpage/pgadmin4
    restart: always
    env_file: .env
    environment:
      - SCRIPT_NAME=/pgadmin
    labels:
      - traefik.enable=true
      - traefik.docker.network=web
      - traefik.http.routers.pgadmin.rule=Host(`${DOMAIN_NAME}`) && PathPrefix(`/pgadmin`)
      - traefik.http.services.pgadmin.loadbalancer.server.port=80
      - traefik.http.routers.pgadmin.tls.certresolver=le
      - traefik.http.routers.pgadmin.entrypoints=websecure
    depends_on:
      - db
    networks:
      - web
      - internal

networks:
  web:
    external: true
  internal:
    external: false

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [May 14, 2023, 5:11am UTC](https://community.traefik.io/t/i-need-help-setting-up-a-custom-api-in-a-docker-compose/18575/22 "2023-05-14T05:11:57Z")

</div>

Is you api running inside your container at `/api`? Otherwise it does not work, because Traefik will of course forward the path in the request. You could use `StripPrefix` middleware.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [May 17, 2023, 5:12am UTC](https://community.traefik.io/t/i-need-help-setting-up-a-custom-api-in-a-docker-compose/18575/23 "2023-05-17T05:12:50Z")

</div>

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

[Previous page](https://community.traefik.io/t/i-need-help-setting-up-a-custom-api-in-a-docker-compose/18575.md?page=1)
