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.
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".
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
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
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
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
or with:
- 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.
About the mounting and the docker.sock?
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?
I hope these tips will help you solve your issue in time! A lot of success! Ask questions if you need more help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With