Docker + Free Hosting: My Personal Portfolio Website Made Easy!
Every engineer dreams of having a personal website to showcase their skills and share knowledge with peers. Following this idea, I’ve decided to create my own portfolio website. This site will display all my skills, projects, and blogs, providing a platform to share my work and help others test their skills. The challenge, however, is to create this portfolio website completely free or for less than 100 rupees.
Pre-Requisites:
- Domain name
- AWS account with basic knowledge of EC2
- Docker Basics
How to start with this project:
- Create a sub-domain from where the website will be accessed.
- Now launch a t2 medium instance using Amazon Linux 2 on AWS. Will use t2 medium till your website is fully ready as t2micro will not be able to handle the load when we try to edit the website using elementor.
- Install docker in the EC2 using these commands.
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo docker run hello-world
sudo systemctl enable docker
docker --version
sudo usermod -a -G docker $(whoami)
newgrp docker
4.Deploy Wordpress and dependencies.
version: '3.7'
services:
traefik:
image: traefik:v2.5
networks:
- traefik-net_default
# container_name: traefik
ports:
- 80:80
- 443:443
volumes:
- /etc/traefik:/etc/traefik
- /home/ec2-user/service/certs:/ssl-certs # Volume for the cert
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: unless-stopped
wordpress:
image: wordpress:latest
# ports:
# - "8080:80"
networks:
- traefik-net_default
labels:
- "traefik.enable=true"
- "traefik.docker.lbswarm=true"
- "traefik.http.routers.wordpress.entrypoints=websecure,web"
- "traefik.http.services.wordpress.loadbalancer.server.port=80"
- "traefik.http.routers.wordpress.rule=Host(`aditya.profile.opsbox.tech`)"
- "traefik.http.routers.wordpress.tls=true" # Traefik Default cert
- "traefik.http.routers.wordpress.tls.certresolver=staging" # Staging cert will be generated
# - "traefik.http.routers.wordpress.tls.certresolver=production" # Production cert will be generated
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress_data:/var/www/html
depends_on:
- db
db:
image: mysql:5.7
networks:
- traefik-net_default
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: rootpassword
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:
networks:
traefik-net_default:
5. Check whether the service is accessible. If it works change the certificate from staging to Production. To know more about traefik check the other Blogs.
6. Follow steps shown in this YouTube video from 37mins import the portfolio template in your hosted WordPress and make the necessary change like adding your experience and blogs to the WordPress.
https://www.youtube.com/watch?v=Lv18fu2EMto&t=3469s
7. Once your website is complete now you can take the backup of the docker volume or Snapshot it in AWS or create the image and hosted the same things back again on a t2 micro instance which will be free for a year. The bill which will be generated from t2 medium can be waved of easily.
Change WORDPRESS_SITEURL and WORDPRESS_HOME url.
Going inside the container:
Exec into mwsql conatiner
mysql -u root -p
USE wordpress;
#Check the current settings
SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');
#change the URL
UPDATE wp_options SET option_value = 'https://newdomain.com' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'https://newdomain.com' WHERE option_name = 'home';
From yaml:
db:
image: mysql:5.7
networks:
- traefik-net_default
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: <pass>
MYSQL_ROOT_PASSWORD: <pass>
WORDPRESS_SITEURL: 'https://newdomain.com'
WORDPRESS_HOME: 'https://newdomain.com'
volumes:
- db_data:/var/lib/mysql