我正在尝试将traefik与我的docker容器一起用于路由。
文件结构为:
docker
├── docker-compose.yml
├── shared
│ └── .htpasswd
└── traefik
├── acme
│ └── acme.json
├── rules.toml
└── traefik.toml
这是traefik.toml:
logLevel = "ERROR"
InsecureSkipVerify = true
defaultEntryPoints = ["https", "http"]
[web]
address = ":8080"
[web.auth.basic]
usersFile = "/shared/.htpasswd"
# Force HTTPS
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[file]
watch = true
filename = "/etc/traefik/rules.toml"
[acme]
email = "test@test.com"
storage="/etc/traefik/acme/acme.json"
entryPoint = "https"
acmeLogging=true
onDemand = false #create certificate when container is created
[acme.dnsChallenge]
provider = "digitalocean"
delayBeforeCheck = 0
[[acme.domains]]
main = "test.com"
[[acme.domains]]
main = "*.test.com"
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "test.com"
watch = true
exposedbydefault = false
docker-compose.yml:
version: "3.5"
services:
traefik:
hostname: traefik
image: traefik:latest
container_name: traefik
restart: always
domainname: ${DOMAINNAME}
networks:
- default
- traefik_proxy
ports:
- "80:80"
- "443:443"
#- "8080:8080"
environment:
#- digitalocean=${DO_AUTH_TOKEN}
- DO_AUTH_TOKEN=${DO_AUTH_TOKEN}
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.frontend.rule=Host:traefik.${DOMAINNAME}"
# - "traefik.frontend.rule=Host:${DOMAINNAME}; PathPrefixStrip: /traefik"
- "traefik.port=8080"
- "traefik.docker.network=traefik_proxy"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ${USERDIR}/docker/traefik:/etc/traefik
- ${USERDIR}/docker/shared:/shared
networks:
traefik_proxy:
external:
name: traefik_proxy
default:
driver: bridge
运行traefik容器后,我试图从存储库中创建另一个容器:
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
--label traefik.backend=hello-hapi \
--label traefik.frontend.rule=Host:hello-hapi.test.com \
--label traefik.docker.network=traefik_proxy \
--label traefik.port=80 \
--name hello_hapi \
gitlab.test.com:5555/myuser/hello_hapi:latest
问题是我无法通过浏览器访问容器。它打印:hello-hapi.test.com’s server IP address could not be found (ERR_NAME_NOT_RESOLVED)
。
但是可以在traefik仪表板和
docker run -it -p 3000:3000 --rm gitlab.test.com:5555/myuser/hello_hapi:latest
在test.com:3000
可能是什么问题?
答案 0 :(得分:0)
您的浏览器正在检查DNS区域中的“ test.com”,然后在该区域中没有“ hello-hapi.test.com”条目。
您需要拥有该域才能为其添加DNS条目。如果不是这种情况,我可以将我的域名命名为“ neekoy.google.com”,而Google对此不会特别满意。
如果要在浏览器中访问它,则可以在计算机上添加本地DNS条目,然后将“ test.com”指向localhost(127.0.0.1)。如果您不知道如何操作,则可以为操作系统使用Google“托管文件”并在其中添加以下行:
127.0.0.1 hello-hapi.test.com test.com www.test.com