Traefik docker image在Windows上不起作用,但在MacOS上起作用? [英] Traefik docker image not working on Windows but working on MacOS?

查看:148
本文介绍了Traefik docker image在Windows上不起作用,但在MacOS上起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它由在MacOS上开发的多个Docker映像组成,我正在尝试使其在Windows上启动。

I have an application that's composed of several Docker images that is being developed on MacOS and I'm trying to get it started on Windows. Most seem to be working, but there's a Traefik load balancer that doesn't.

在MacOS上它可以正常工作,但是在Windows上,无论我访问哪个URL,它都能为我提供服务404,实际内容只是找不到404页面。

On MacOS it just works, but on Windows, whatever URL I access, it gives me a 404, the actual content which is just "404 page not found".

Traefik配置如下:

The Traefik configuration looks like this:

logLevel = "INFO"
defaultEntryPoints = ["http", "https"]
[entryPoints]
  [entryPoints.http]
   address = ":80"
  [entryPoints.https]
   address = ":443"
    [entryPoints.https.tls]
    [entryPoints.https.tls.defaultCertificate]
      certFile = "/certs/cert.pem"
      keyFile = "/certs/cert.pem"
# Connection to docker host system (docker.sock)
[docker]
watch = true
domain = "localhost"
[file]
 [backends]
  [backends.backend-mixpanel]
     [backends.backend-mixpanel.servers]
      [backends.backend-mixpanel.servers.mixpanel]
        url = "https://api.mixpanel.com"
        weight = 10
  [backends.backend-yieldify]
     [backends.backend-yieldify.servers]
      [backends.backend-yieldify.servers.yieldify]
        url = "https://td.yieldify.com/"
        weight = 0
 [frontends]
     [frontends.frontend-mixpanel]
       backend = "backend-mixpanel"
      [frontends.frontend-mixpanel.routes.one]
        rule = "HostRegexp:localhost,{catchall:.*};Path:/mixpanel/{.*};PathPrefixStripRegex:/{mixpanel}"
        priority=10
     [frontends.frontend-yieldify]
       backend = "backend-yieldify"
      [frontends.frontend-yieldify.routes.two]
        rule = "HostRegexp:localhost,{catchall:.*};Path:/yieldify/{.*}"
        priority=0

虽然Dockerfile包含:

While the Dockerfile contains:

FROM traefik:alpine

RUN apk add --update openssl

RUN mkdir -p /certs

RUN openssl req -x509 -newkey rsa:2048 -keyout key.pem -out ca.pem -days 1080 -nodes -subj '/C=UK/ST=London/L=London/O=ProjectX/OU=Engineering team/CN=local.wif'

RUN cat key.pem ca.pem > /certs/cert.pem

相关的docker-compose.yml部分包含:

The relevant docker-compose.yml section contains:

  lb:
    image: load-balancer
    build: ${WORKSPACE}/go-home/load_balancer
    ports:
    - 80:80
    - 443:443
    links:
    - wifi-ui-dev
    - wifi-ui-prod
    - portal
    - wifi-api
    env_file:
    - .env
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro,delegated
    - ${PWD}/load_balancer/traefik.toml:/etc/traefik/traefik.toml:ro,delegated

当我收到404时,对于该Docker映像,什么也没有发送到控制台(stdout和stderr)。

And when I get the 404 I get nothing sent to the console (stdout and stderr) for that Docker image.

任何想法发生了什么事或如何更接近其无法正常工作的原因?

Any ideas what's going on or how to get closer to a reason why it's not working?

我最担心的是套接字的数量:

One of my worries was the socket volume:

- /var/run/docker.sock:/var/run/docker.sock:ro,delegated

检查跑步情况容器,文件看起来像一个套接字:

Checking the running container, the file looks like a socket:

/ # ls -laF /var/run/docker.sock
srw-rw----    1 root     root             0 Sep  2 11:04 /var/run/docker.sock=

以防万一,我尝试用以下命令替换该行:

Just in case, I tried replacing that line with:

- //./pipe/docker_engine:/var/run/docker.sock

或:

- type: npipe
  source: ////./pipe/docker_engine
  target: /var/run/docker.sock
  consistency: delegated

两者都导致套接字看起来像目录:

both of which resulted in the socket looking like a directory:

/ # ls -laF /var/run/docker.sock
total 4
drwxr-xr-x    2 root     root            40 Sep  3 14:52 ./
drwxr-xr-x    1 root     root          4096 Sep  3 14:57 ../


推荐答案

好的,我会尽力指导您解决许多问题。

OK, I will try to coach you in a number of your issues.


  • 没有找到404(只是一个句子)-通常是traefik配置问题。不是常规网站404。您可以通过查看Traefik容器的日志来验证这一点。

  • 当Traefik的启动顺序不正确时,我也遇到了404的类似问题。有时我们会在Docker(Swarm)堆栈外部分别部署Traefik。然后,我们部署堆栈(或其他组件)。您可以通过例如指定订单docker-compose.yml文件。这个 depends_on是不准确的,因为它仅测试组件是否已启动,而不是作为应用程序完全启动。

  • 由于您的配置在Mac上运行,因此我认为traefik 404并非由于Docker(Traefik)网络配置所致。

  • 请确保您使用的是Treafik版本。自Traefic 2以来,发生了一些重要变化。我使用:traefik:v1.7.11-alpine。

  • 请确保将 traefik.enable显式设置为true。我们发现,如果需要此设置,则每个环境都不同。

  • 如果部署正在运行的网站,则可以使用Traefik控制台(通过端口8080)查看已配置的内容。您会看到前端规则和后端。

  • 环境文件是 .env。将点文件放在Windows上需要采取特殊措施,例如通过cygwin或Git bash。假定该文件已存在。

  • 404 not found (just as a sentence) - is typically a traefik config issue. Not a regular website 404. You can verify this by looking in the logs of the Traefik container.
  • I had similar issues with 404 when Traefik was not started in the right order. We sometimes deploy Traefik outside our Docker (Swarm) stack seperately. Then we deploy the stack (or other components). You can specify the order via e.g. a docker-compose.yml file. This 'depends_on' is not accurate, because it only tests whether the component is started, not that is completely started as an application.
  • Because your config runs on Mac my assumption is that the traefik 404 is not due to the Docker (Traefik) network configuration.
  • Be sure which version you use of Treafik. Since Traefic 2 there were a few important changes. I use: traefik:v1.7.11-alpine.
  • Be sure that "traefik.enable" should explicitly be set to true. We saw that it differs per environment if this setting is needed.
  • If you deploy a running website, you can use the Traefik console (via port 8080) to see what you have configured. You see the frontend rules and the backends.
  • The environment file is is '.env'. Putting dot-files on Windows requires special actions, e.g. via cygwin or Git bash. Assumed is that the file is existing.

关于安装和docker.sock?

About the mounting and the docker.sock?


  • 分享股票。在Windows上,打开Docker桌面,转到共享驱动器选项卡。添加驱动器,例如作为示例,我将K映射到例如K:\数据。

  • 下面从docker-compose.yml文件中找到了许多示例。在这些示例中,我使用份额 K => k:/ data。

第一个示例显示了如何在适用于Windows的Docker上启动完整的Jenkins环境。在Jenkins环境中,对Docker Engine进行了引用,因此对Windows上的docker.sock进行了引用。
这是我的Docker for Windows环境中的我每天使用的

The first example shows how to start a complete Jenkins environment on Docker for Windows. From within the Jenkins environment reference is made to the Docker Engine, so a reference is made to docker.sock on Windows. This is what I daily use in my Docker for Windows environment. It works fine!

version: '3'
services:
  jenkins:
    image: docker-jenkins-maven-npm-oc:latest
    ports:
      - "8888:8080"
    volumes:
      - //k/data/var/jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
  geosolschmea:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=somedatabase
      - MYSQL_USER=johan
      - MYSQL_PASSWORD=bladibladibla
    volumes:
      - //k/data/var/mysql-data:/var/lib/mysql
    ports:
      - "3306:3306"

Windows上另一个docker-compose.yml文件中的Spring引导应用程序:

Another Spring boot application on Windows in a docker-compose.yml file:

  geosolutionapp:
    image: myuser/geosolutions:latest
    build:
      context: ./
      dockerfile: Dockerfile
    depends_on:
      - geosolschmea
    environment:
      - SCDATALIMIT=100000
    ports:
      - 8080:8080
    volumes:
      - //k/data/spring-boot-app:/data/spring-boot-app
    networks:
      - geosolutionsnet

对于Traefik,docker-compose.yml可能看起来像(在Linux上,Amazon EC2)。这也将允许您显示Traefik仪表板。使用它来查看您拥有哪些前端和后端。稍微更改卷即可在Windows的Docker上运行它。

For Traefik a docker-compose.yml could look like (on Linux, Amazon EC2). This will also allow you to show the Traefik dashboard. Use this to see which frontends and backends you have. Changing the volumes slightly and you have it run on Docker for Windows.

如果更改Treafik文件的路径,则可以在Windows的Docker上轻松运行它:

You can easily run this on Docker for Windows if you change the paths to the Treafik files:

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - //k/data/traefik/traefik.toml:/traefik.toml
      - //k/data/traefik/acme.json:/acme.json

每天在Linux上运行的完整运行(实时)示例为:

The complete working (live) example running daily on Linux is:

version: '3'
services:
  traefik:
    image: traefik:v1.7.11-alpine
    container_name: traefik
    restart: always
    networks:
      - geosolutionsnet
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/ec2-user/traefik/traefik.toml:/traefik.toml
      - /home/ec2-user/traefik/acme.json:/acme.json
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    labels:
      - "traefik.docker.network=geosolutionsnet"
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:yourwebsite.nl;PathPrefix:/traefik"
      - "traefik.port=8080"
      - "traefik.protocol=http"
      - "traefik.backend=traefik"

在Windows版Docker上使用Traefik时,我使用它来连接traefik.toml文件中的Docker引擎:

When using Traefik on Docker for Windows, I use this to connect to the docker Engine in the traefik.toml file:

[docker]
  endpoint = "unix:///var/run/docker.sock"
  domain = "yourwebsite.nl"
  watch = true
  exposedByDefault = false

如果您在Windows的Docker上无法获得Traefik的路由工作,您可以将其用作框架,并首先从 docker hello world示例开始,然后通过Treafik对其进行访问。获得适用于Windows的Docker上的Traefik的基本路线后,您可以逐步添加您的真实应用程序。可能觉得这很长一段路,但是根据我们的经验,这很快就会奏效。

If you have trouble getting the routing work for Traefik on Docker for Windows, you can use this as a skeleton and start with a 'docker hello world' example first and get it accessable via Treafik. After getting a basic route working Traefik on Docker for Windows, you can step by step add your real application. This may be felt as a long way, but in our experience this works fast.

当然,并非所有端口都应该对外界可见。您可以使用较新版本的docker-compose.yml文件。

Of course, not all ports should be visible to the outside world. You could use a newer version of the docker-compose.yml file.

使用Treafik的另一个组件可能是:

Another component using Treafik could be like:

  geosolutionapp:
    image: myuser/myproduct:latest
    environment:
      - slackBotToken=xyz-etc
    ports:
      - 8080
    networks:
      - geosolutionsnet
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=geosolutionsnet"
      - "traefik.frontend.rule=Host:myapplication.nl"
      - "traefik.port=8080"
      - "traefik.protocol=http"

另一个例子:

slackbotsimple:
    image: myuser/slackbotsimple:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - traefik
    environment:
      - slackBotToken=xoxb-etc-etc-etc

仍然卡在docker.sock上吗?

Still stuck on the docker.sock?


  • 如果上述方法没有帮助,您还可以使用以下方法:docker run -v //var/run/docker.sock :/var/run/docker.sock ...

  • Powershell:运行$ Env:COMPOSE_CONVERT_WINDOWS_PATHS = 1

  • Git bash:$ export COMPOSE_CONVERT_WINDOWS_PATHS = 1

    $ docker-compose down&& docker-compose up -d

  • 确保/var/run/docker.sock具有正确的权限。在某些情况下,我必须通过以下方式手动设置权限:$ docker exec -u 0 -it bash ...然后#chmod 777 /var/run/docker.sock

  • If the above does not help, you can also use an approach like: docker run -v //var/run/docker.sock:/var/run/docker.sock ...
  • Powershell: run $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1
  • Git bash: $ export COMPOSE_CONVERT_WINDOWS_PATHS=1
    $ docker-compose down && docker-compose up -d
  • Be sure the /var/run/docker.sock has the right permissions. In some cases I have to manually set the permissions via this: $ docker exec -u 0 -it bash ... and then # chmod 777 /var/run/docker.sock

我希望这些技巧能帮助您及时解决问题!大获成功!询问问题是否需要更多帮助。

I hope these tips will help you solve your issue in time! A lot of success! Ask questions if you need more help.

这篇关于Traefik docker image在Windows上不起作用,但在MacOS上起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆