This post basically highlights how you can setup your blogging site (or any static website) using Hugo running in a Docker Swarm environment with Traefik. This whole setup is done on AWS, but it could be replicated to any cloud service provider. In my case its only a single node docker swarm cluster.
Install Docker on an Amazon EC2 instance
-
The steps to spin up EC2 instance on AWS is here
-
Connect to your instance
1
|
ssh -i /path/inlets.pem ec2-user@ec2-54-254-122-14.ap-southeast-1.compute.amazonaws.com
|
-
Update the installed packages and package cache on your instance, install docker and start the docker service.
1
2
3
|
sudo yum update -y
sudo amazon-linux-extras install docker
sudo service docker start
|
-
Add the ec2-user to the docker group so you can execute Docker commands without using sudo.
1
|
sudo usermod -a -G docker ec2-user
|
Initialize the Docker Swarm
1
|
docker swarm init --advertise-addr eth0
|
List nodes in the swarm
1
2
3
|
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
9fj7jdv4zfkgp6nlg229qqtvr * sujaypillai.dev Ready Active Leader 18.06.1-ce
|
Definition of docker stack to run Traefik
- The above stack uses Traefik version 1.7.13
- Traefik routes all incoming http/https request from the public address of the server and relays those request to the targeted service running privately on the server following some rules. This is achieved by publishing the ports 80 & 443.
- You can configure Traefik to use an ACME provider (Let’s Encrypt) for automatic certificate generation. All the flags
acme.*
are related to ACME configuration and the certificates generated are stored in a volume named traefik_certs
.
- Use
htpasswd
utility to create an encrypted password and save the generated password in a file named htpasswd which is passed in the config section.
1
|
htpasswd -c htpasswd administartor
|
- The
EMAIL
& DOMAIN
are set as an environment variable on the host.
Deploying the Traefik service as proxy
1
|
docker stack deploy -c docker-stack-traefik.yml proxy
|
1
2
3
|
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
utjpltombxnr proxy_traefik replicated 1/1 traefik:1.7.13
|
1
2
3
|
docker service ps proxy_traefik
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ksaooufxkgsn proxy_traefik.1 traefik:1.7.13 sujaypillai.dev Running Running 8 months ago *:443->443/tcp,*:80->80/tcp
|
Deploying blogging site (Hugo)
1
|
docker stack deploy -c docker-stack-sujaypillai.yml web
|
1
2
3
4
|
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
utjpltombxnr proxy_traefik replicated 1/1 traefik:1.7.13
5s2blx0kicj0 web_website replicated 1/1 klakegg/hugo:0.63.2 *:1313->1313/tcp
|
1
2
3
|
docker service ps web_website
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
dewhzxakrfei web_website.1 klakegg/hugo:0.63.2 sujaypillai.dev Running Running 8 months ago
|