Traefik docker image not working on Windows but working on MacOS?

孤街醉人 提交于 2019-12-05 02:08:29

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

  • 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.

About the mounting and the docker.sock?

  • Make a share. On Windows, open your Docker Desktop, go to tab "Shared drives". Add a drive, e.g. D or K. As an example I mapped K to e.g. K:\data.
  • Below you find a number of examples from a docker-compose.yml file. I use in these examples the share "K => k:/data".

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"

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

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.

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

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"

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

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.

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

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"

And another example:

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

Still stuck on the 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.

To run an linux based docker image on windows, there are some requirements that needs to be met: Windows 10 Pro or higher, with Hyper-V support enabled.

You nee also to install “Docker for Windows.exe” which is a manager app that sets up a “Hyper-V VM” named: MobyLinuxVM, which contains a minimal linux system, that is able to run docker containers. hope that helps!

Looks like issue with docker-compose.yml

This line:

- ${PWD}/load_balancer/traefik.toml:/etc/traefik/traefik.toml:ro,delegated

And this one:

build: ${WORKSPACE}/go-home/load_balancer

Can you use relative path instead of system variables? Some explanation is written here

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!