# HTTP Basic Auth for Docker routes

**URL:** <https://community.traefik.io/t/http-basic-auth-for-docker-routes/24496>\
**Category:** Traefik v3 (latest)\
**Tags:** middleware, docker\
**Created:** [September 19, 2024, 9:54pm UTC](https://community.traefik.io/t/http-basic-auth-for-docker-routes/24496 "2024-09-19T21:54:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s0mbre](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/s0mbre/32/8288_2.png) [@s0mbre](https://community.traefik.io/u/s0mbre)\
**Post date:** [September 19, 2024, 9:54pm UTC](https://community.traefik.io/t/http-basic-auth-for-docker-routes/24496/1 "2024-09-19T21:54:07Z")

</div>

I want to enable HTTP Basic Auth on a number of Docker containers with Traefik labels. I'm doing it like so:

```yml
pgadmin:
    labels:
      - traefik.enable=true
        # make accessible via my.host.com/pgadmin/...
      - traefik.http.routers.pgadmin.rule=(Host(`my.host.com`) && PathPrefix(`/pgadmin`))
        # HTTPS only
      - traefik.http.routers.pgadmin.entrypoints=https
      - traefik.http.routers.pgadmin.tls.certresolver=le
        # compression middleware
      - traefik.http.middlewares.my-compress.compress=true
        # basic auth middleware
      - traefik.http.middlewares.admin-auth.basicauth.users=admin:$$apr1$$ur5Gr99C$$f354Cu/lqKJYOv5M/eNdW0
        # apply middlewares to route
      - traefik.http.routers.pgadmin.middlewares=my-compress@docker,admin-auth@docker

```

And the middleware(s) don't seem to work! I can still browse to [my.host.com/pgadmin](http://my.host.com/pgadmin) and see no authentication.

---

<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:** [September 20, 2024, 6:30am UTC](https://community.traefik.io/t/http-basic-auth-for-docker-routes/24496/2 "2024-09-20T06:30:37Z")

</div>

Have you tried without `@docker`? This works for me:

```auto
    labels:
      - traefik.enable=true
      - traefik.http.routers.mydashboard.rule=Host(`traefik.example.com`)
      - traefik.http.routers.mydashboard.service=api@internal
      - traefik.http.routers.mydashboard.middlewares=myauth
      - traefik.http.middlewares.myauth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/

```

From [simple Traefik example](https://github.com/bluepuma77/traefik-best-practice/tree/main/docker-traefik-dashboard-letsencrypt).

Also, try to reverse your order of middlewares, first auth, then compress.

Enable and check Traefik debug log ([doc](https://doc.traefik.io/traefik/observability/logs/#level)).

Finally note that some browsers/clients will cache the entered user/pass for a site for some time, so you won’t be asked any time.

---

<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:** [September 26, 2024, 10:17pm UTC](https://community.traefik.io/t/http-basic-auth-for-docker-routes/24496/3 "2024-09-26T22:17:18Z")

</div>

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