PiStacks Home Setup: Traefik

Welcome to my PiStacks Home Setup tutorial, where I will demonstrate how to setup lots of stacks on a raspberry pi docker swarm cluster.

In this post we will setup Traefik, a modern reverse proxy for microservices.

Applications to Cover

During this series of blogposts, I will be covering the following:

  • Traefik
  • Dynamic DNS
  • Blog
  • Monitoring with Prometheus
  • Monitoring with InfluxDB
  • Logging with Loki
  • Object Storage with Minio

Build Traefik for ARM

Next we will build our docker image for Traefik on ARM.

In our Dockerfile we will build a image for Traefik version 1.7.14 for ARM:

FROM pistacks/alpine


ADD https://github.com/containous/traefik/releases/download/v${TRAEFIK_VERSION}/traefik_linux-${ARCH} ./traefik_linux-${ARCH}  
ADD traefik_linux-${ARCH} /traefik

RUN apk add --no-cache ca-certificates \  
    && chmod +x /traefik \
    && rm -rf /var/cache/apk/*

EXPOSE 80 8080 443

ENTRYPOINT ["/traefik"]  

Once you saved the above content in a Dockerfile, let's build our image:

$ docker build .

Once your image is build you will get a image id:

Successfully built 28395b34c3ed  

Tag that image to the username, repo and tag of your choice, in my example I want to tag it to the following:

$ docker tag 28395b34c3ed pistacks/traefik:1.7.14

Once we have tagged our image, login to our dockerhub account and push the image to the registry:

$ docker login
$ docker push pistacks/traefik:1.7.14

Deploy to Swarm

Now that our image has been pushed to dockerhub, we can deploy Traefik to our Raspberry Pi Swarm.

First we need to create a overlay network that we will use for all the network traefik that will be public, in other words, traverse through Traefik:

Let's create a network called traefik:

$ docker network create --driver overlay traefik

Once our network has been created, create a file called traefik/docker-compose.yml in the mentioned directory:

$ mkdir traefik && cd traefik
$ vim docker-compose.yml

And provide the following content:

version: "3.2"

    image: pistacks/traefik:1.7.14
      - 80:80
      replicas: 1
          - node.role == manager
      - /var/run/docker.sock:/var/run/docker.sock
    command: >
      - traefik

    external: true

Once you have saved the content, deploy the traefik service:

$ docker stack deploy -c docker-compose.yml proxy

You have now deployed Traefik on your Raspberry Pi Docker Swarm.

In the following posts we will deploy backend services on our Raspberry Pi Docker Swarm Cluster.