Build a Traefik Proxy Image for Your Raspberry Pi on Docker Swarm
In this post we will setup a Docker Image for Traefik Proxy on the ARM Architecture, specifically on the Raspberry Pi, which we will deploy to our Raspberry Pi Docker Swarm.
Then we will build and push our image to a registry, then setup traefik and also setup a web application that sits behind our Traefik Proxy.
What is Traefik
Traefik is a modern load balancer and reverse proxy built for micro services.
Dockerfile
We will be running Traefik on Alpine 3.8:
1234567891011121314
FROM rbekker87/armhf-alpine:3.8
ENV TRAEFIK_VERSION 1.7.0-rc3
ENV ARCH arm
ADD https://github.com/containous/traefik/releases/download/v${TRAEFIK_VERSION}/traefik_linux-${ARCH} /traefik
RUN apk add --no-cache ca-certificates \&& chmod +x /traefik \&& rm -rf /var/cache/apk/*
EXPOSE808080443ENTRYPOINT["/traefik"]
Build and Push
Build and Push your image to your registry of choice:
Check if the services in your stack is running. Since our deploy mode was global, there will be a replica running on each node, and in my swarm I’ve got 3 nodes:
123
$ docker stack services proxy
ID NAME MODE REPLICAS IMAGE PORTS
16x31j7o0f0r proxy_traefik global 3/3 rbekker87/armhf-traefik:1.7.0-rc3 *:80->80/tcp,*:8080->8080/tcp
Deploy a Web Service hooked up to Traefik
Pre-Requirement:
To register subdomains on the fly, set you DNS for your domain to the following (im using pistack.co.za in this example):
pistack.co.zaAx.x.x.x
*.pistack.co.zaAx.x.x.x
Next, we will deploy we app that will be associated to our Traefik service domain, so we will inform Traefik that our web app fqdn and port that will be registered with the proxy.
In the above compose, you will notice that our traefik backend is set to our service name, our port is the port that the proxy will forward requests to the containers port, since the proxy and the whoami container is in the same network, they will be able to communicate with each other. Then we also have our frontend rule which will be the endpoint we will reach our application on.
Deploy the stack:
12
$ docker stack deploy -c whoami.yml web
Creating service web_whoami
List the tasks running in our web stack:
123
$ docker stack services web
ID NAME MODE REPLICAS IMAGE PORTS
31ylfcfb7uyw web_whoami replicated 3/3 rbekker87/golang-whoami:alpine-amrhf
Once all the replicas is running, move along to test the application
Testing our Application:
I have 3 replicas each running on their own container, so each container will respond with its own hostname:
12345
$ docker service ps web_whoami
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ivn8fgfosvgd web_whoami.1 rbekker87/golang-whoami:alpine-amrhf rpi-01 Running Running 26 minutes ago
rze6u6z56aop web_whoami.2 rbekker87/golang-whoami:alpine-amrhf rpi-02 Running Running 26 minutes ago
6fjua869r498 web_whoami.3 rbekker87/golang-whoami:alpine-amrhf rpi-04 Running Running 23 minutes ago