Træfik, Docker and your vps part 1
I love playing with servers and if you do too keep reading. I will show you how to setup a Traefik proxy and docker environment on your VPS.
I have an "amazing" website here www.themwebs.me it's fast simple and cheaply hosted with a yearly fixed cost on a VPS with www.hostinger.com.
I wanted a space where I could play with stuff, containers, apis, test tools, test web frameworks, backend and frontend.
Specifically: I needed a place to host backend APIs that I might create like this one made with with python using Flask.
I have these apps running:
Now if playing with servers is not your jam, stop reading and head over to your favourite backend as service or serverless platforms those are great too I use them often.
knowledge about docker is assumed. I will be focusing on Traefik and configuring it more than docker basics.
Ready?
Let's go.
What
We will be building a small microservices architecture on our server using docker.
It looks like this:
Why
So that we can quickly deploy backend api using any language. It's fun to try out new languages and frameworks e.g Deno, Rust and maybe some Go lang in the future. This way we will be able to deploy the code and have live URL's to test with.
How
We will be using docker, docker compose and Traefik as the proxy to containers.
I have already set up a repo with different "services" here.
It includes:
- one folder per service, each service has it's own Dockerfile
- a single
docker-compose
file to start the services from the root. - traefik.toml
- traefik_dynamic.toml
Traefik
Traefik is an open-source Edge Router that makes publishing your services a fun and easy experience. It receives requests on behalf of your system and finds out which components are responsible for handling them. source: Traefik
Imagine you have a website at www.website.com and an api at api.website.com, Traefik will direct the request to the appropriate service based on the sub domain.
Traefik will also help create SSL certificates using ACME provider Lets Encrypt.
This is configured via a .toml configuration file called traefik.toml and traefik_dynamic.toml. In these configuration files we specify:
- Entry points,
- Routers
- Middlewares, e.g SSL certificate resolver.
- Services Traefik supports
traefik.toml
Read file here
traefik_dynamic.toml
Read file here
Admin page running on monitor.company.com domain, secured behind a username and password
SimpleAuth middleware
Here is sample of my server showing the containers running on their respective ports
That will do for now, take a break and we will dive into the docker parts in part 2.