问题描述
我将Docker与Traefik和Django cookiecutter一起使用。我想向其添加基本身份验证以将其屏蔽。我的docker compose yaml文件如下所示:
version: '3'
volumes:
production_postgres_data: {}
production_postgres_data_backups: {}
production_traefik: {}
services:
...
traefik:
build:
context: .
dockerfile: ./compose/production/traefik/Dockerfile
image: myod_production_traefik
depends_on:
- django
volumes:
- production_traefik:/etc/traefik/acme:z
ports:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.auth.basicauth.users=myod:$$2y$$05$......"
...
但是,当我运行docker-compose -f production.yml up
时,我仍然可以访问该网站而无需进行身份验证。我想念什么?
解决方法
您必须使用中间件启用HTTP Basic身份验证。 因此,您应该添加标签:
aria-readonly="true"
至少根据此https://blog.creekorful.com/2020/01/how-to-expose-traefik-2-dashboard-securely-docker-swarm/,您应该能够按照您的想象进行操作。