我是一個完整的 docker noob。剛剛按照教程安裝了 docker 和 docker-compose 以及 portainer。
現在我想在 portainer 上設定 traefik 反向代理。
這是 /etc/traefik 中的 traefik.yml 檔案
global:
checkNewVersion: true
sendAnonymousUsage: false # true by default
# (Optional) Log information
# ---
# log:
# level: ERROR # DEBUG, INFO, WARNING, ERROR, CRITICAL
# format: common # common, json, logfmt
# filePath: /var/log/traefik/traefik.log
# (Optional) Accesslog
# ---
# accesslog:
# format: common # common, json, logfmt
# filePath: /var/log/traefik/access.log
# (Optional) Enable API and Dashboard
# ---
api:
dashboard: true # true by default
insecure: true # Don't do this in production!
# Entry Points configuration
# ---
entryPoints:
web:
address: :80
# (Optional) Redirect to HTTPS
# ---
# http:
# redirections:
# entryPoint:
# to: websecure
# scheme: https
websecure:
address: :443
# Certificates configuration
# ---
# TODO: Custmoize your Cert Resolvers and Domain settings
#
這是 docker-compose 檔案:
version: '3'
volumes:
traefik-ssl-certs:
driver: local
services:
traefik:
image: "traefik:v2.5"
container_name: "traefik"
ports:
- "80:80"
- "443:443"
# (Optional) Expose Dashboard
- "8080:8080" # Don't do this in production!
volumes:
- /etc/traefik:/etc/traefik
- traefik-ssl-certs:/ssl-certs
- /var/run/docker.sock:/var/run/docker.sock:ro
但是當我嘗試啟動容器時,出現此錯誤:
2021/12/08 18:08:07 命令 traefik 錯誤:yaml:第 19 行:未找到預期的密鑰
當我從 docker-compose 檔案中洗掉“服務”下的整個“卷”部分時,我可以讓容器運行,但我需要它來設定我的 traefik。我不知道我做錯了什么,因為我正在關注這個 1:1 的視頻教程
uj5u.com熱心網友回復:
你能分享整個終端日志嗎?這是容器內部的錯誤嗎?
無論如何,我認為您應該檢查您的 traefik.yml 縮進。有一些不同級別的鍵,YAML 對此非常敏感。我特別講:
- 全球的
- 檢查新版本
- 發送匿名使用
- 介面
檢查它們之前的空格數。
uj5u.com熱心網友回復:
我無法重新創建您的確切錯誤訊息,但是在使用您的確切traefik.yml組態檔(如問題中發布的)時出現錯誤,因為語法無效(如另一個答案中指出的)。
我將撰寫檔案減少到最低限度:
version: '3'
services:
traefik:
image: "traefik:v2.5"
container_name: "traefik"
volumes:
- 'c:\temp\traefik\etc\traefik.yml:/etc/traefik/traefik.yml'
traefik.yml如您所見,僅將檔案安裝到容器中。該檔案如下所示,洗掉了注釋掉的行:
global:
checkNewVersion: true
sendAnonymousUsage: false # true by default
api:
dashboard: true # true by default
insecure: true # Don't do this in production!
entryPoints:
web:
address: :80
websecure:
address: :443
docker-compose up對此運行 a會出現以下錯誤:
c:\Temp\traefik>docker-compose up
[ ] Running 1/0
- Container traefik Created 0.0s
Attaching to traefik
traefik | 2021/12/09 08:44:36 command traefik error: no valid configuration found in file: /etc/traefik/traefik.yml
traefik exited with code 1
當我修復traefik.yml檔案中的縮進(并打開除錯日志記錄)時,我有這個:
global:
checkNewVersion: true
sendAnonymousUsage: false # true by default
api:
dashboard: true # true by default
insecure: true # Don't do this in production!
entryPoints:
web:
address: :80
websecure:
address: :443
log:
level: DEBUG
docker-compose up再次運行我現在得到這個:
c:\Temp\traefik>docker-compose up
[ ] Running 2/2
- Network traefik_default Created 0.2s
- Container traefik Created 29.5s
Attaching to traefik
traefik | time="2021-12-09T08:49:30Z" level=info msg="Configuration loaded from file: /etc/traefik/traefik.yml"
traefik | time="2021-12-09T08:49:30Z" level=info msg="Traefik version 2.5.4 built on 2021-11-08T17:41:41Z"
traefik | time="2021-12-09T08:49:30Z" level=debug msg="Static configuration loaded {\"global\":{\"checkNewVersion\":true},\"serversTransport\":{\"maxIdleConnsPerHost\":200},\"entryPoints\":{\"traefik\":{\"address\":\":8080\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"udp\":{\"timeout\":\"3s\"}},\"web\":{\"address\":\":80\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"udp\":{\"timeout\":\"3s\"}},\"websecure\":{\"address\":\":443\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"udp\":{\"timeout\":\"3s\"}}},\"providers\":{\"providersThrottleDuration\":\"2s\"},\"api\":{\"insecure\":true,\"dashboard\":true},\"log\":{\"level\":\"DEBUG\",\"format\":\"common\"},\"pilot\":{\"dashboard\":true}}"
traefik | time="2021-12-09T08:49:30Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://doc.traefik.io/traefik/contributing/data-collection/\n"
traefik | time="2021-12-09T08:49:30Z" level=info msg="Starting provider aggregator.ProviderAggregator {}"
...
...
所以可以看到traefik啟動了。這不一定與您遇到的問題相同,但它顯示了如何解決問題。一旦你知道你的 traefik 配置是好的,你可以添加 DEBUG 日志,然后嘗試添加其他卷和配置,看看它們是否也正常。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/378419.html
標籤:码头工人 docker-compose 文件 搬运工
