A simple Traefik web hosting architecture orchestrated by Docker Swarm. Designed for quick and easy hosting and routing of multiple self-contained Docker images. This architecture offers a straightforward approach to link URLs to containerized applications. All incoming HTTP traffic is rerouted to a secure and encrypted HTTPS connection certified by Let's encrypt.
- Linux web server - DigitalOcean droplet or similar.
- IPv4 - IP address to the web server.
- Docker - Up to date version of Docker running on server.
- Docker image - Dockerised web application hosted on Docker Hub.
- Domain name - URL routed to the web server.
- Create the required directories for storing TSL certificates and logs (can be relocated in
traefik/docker-compose.yml
).
mkdir logs && mkdir letsencrypt
- Set the email and IP environment variables to your information.
export WEBHOST_EMAIL=email@example.com # Your email address
export WEBHOST_IP=192.168.0.1 # IP to server
- Initiate the Docker Swarm cluster.
docker swarm init --advertise-addr ${WEBHOST_IP}
- Deploy the Traefik container.
docker stack deploy -c traefik/docker-compose.yml webhost
- Set the website environmental variables and deploy website container.
export WEBSITE_SERVICE=website1 # Any unique tag
export WEBSITE_IMAGE=nginx # Image name on Docker Hub
export WEBSITE_URL=myurl.com # Without www
docker stack deploy -c website/docker-compose.yml ${WEBSITE_SERVICE}
- Repeat step 5 for every website to be deployed.
- When ready to deploy, change the Let's Encrypt URL in
traefik/docker-compose.yml
to deployment mode, and redeploy webhost container.
FROM: https://acme-staging-v02.api.letsencrypt.org/directory
TO: https://acme-v02.api.letsencrypt.org/directory
docker stack deploy -c traefik/docker-compose.yml webhost