After a year or two spending quite a lot of time into docker and more specifically docker swarm, I found it quite tedious to write up docker-compose files for specific stacks that you are working on. I also felt the need for a docker swarm compose package manager.
Fair enough, you store them on a central repository and then you can reuse them as you go, and that is exactly what I did, but I felt that perhaps other people have the same problem.
The Main Idea
So the main idea is to have a central repository with docker swarm stacks, that you can pick and choose what you want, pull down the repository and use environment variables to override the default configuration and use the deploy script to deploy the stack that you want.
Future Ideas
In the future I would like to create a cli tool that you can use to list stacks, as example:
1 2 3 4 5 6 |
|
Listing stacks by category:
1 2 3 |
|
Deploying a stack:
1 2 3 4 5 6 7 8 |
|
At the time of writing the cli tool is not available yet, but the list of available templated docker stack repositories are availabe at github.com/bekkerstacks
What are we doing today
In this tutorial we will deploy a Traefik proxy on Docker Swarm. I will be demonstrating the deployment on my Mac, and currently I have only docker installed, without a swarm being initialized.
If you already have a swarm initialized and running this on servers, you can skip the local dev section.
Local Dev
We will be initializing a 3 node docker swarm on a mac using docker-in-docker. Get the repository:
1
|
|
Switch to the directory and deploy the swarm:
1 2 3 4 5 6 7 |
|
As you can see we have a 4 node docker swarm running on our local dev environment to continue.
Deploy Traefik
To deploy traefik in HTTPS mode, we need to set 3 environment variables: EMAIL
, DOMAIN
, PROTOCOL
. We also need to setup our DNS to direct traefik to our swarm. In my case I will be using 1.2.3.4
as the IP of my Manager node and using the domain mydomain.com
The DNS setup will look like this:
1 2 |
|
And if you are using this locally, you can setup your /etc/hosts
to 127.0.0.1 traefik.mydomain.com
Clone the repository:
1
|
|
Change the the repository and deploy the stack:
1 2 3 4 5 6 7 8 |
|
Verify that the Traefik service is running:
1 2 3 |
|
Navigating to the Traefik Dashboard, after providing your username and password, you should see the Traefik UI:
Note: I don’t own mydomain.com therefore I am using the traefik default cert, that will be why it’s showing not secure.
Deploy Traefik in HTTP Mode
If you want to deploy Traefik in HTTP mode rather, you would use:
1 2 3 4 5 6 7 8 |
|
Navigating to the Traefik Dashboard, after providing your username and password, you should see the Traefik UI:
More Info
In future posts, I will demonstrate how to deploy other stacks using bekkerstacks.
Have a look at the repositories on github for more info:
- https://github.com/bekkerstacks
- https://github.com/bekkerstacks/docker-swarm
- https://github.com/bekkerstacks/traefik
Thank You
Let me know what you think. If you liked my content, feel free to checkout my content on ruan.dev or follow me on twitter at @ruanbekker