I’ve been meaning to play with docker, containers in general, for quite sometime. As a result, I’ve set this website to run inside a docker container. Brief of what it entails below –
Steps
- Register an account with Google cloud – GCP
- Deploy a pico size compute node (or whatever comes under free offer)
- Select a n-1 version of Ubuntu LTS minimal image
- Go to GCP console network external IP address and change address from ephemeral to static
- Head over to your DNS provider’s control panel
- Set A-record to the public IP of your compute node
- Set a CNAME for ‘www’ to your A-record or node’s public IP address
- Proceed when DNS propagation is complete (test with dig tools). It may take 2-3 hours
- Create and mount a 4G swapfile
- Install docker, docker-compose, git
- Find a suitable container that packages, an all in one — a blog or CMS package + Webserver + SSL + DB + PHP
- Deploy container using docker-compose
- Access blog or CMS GUI over http/s and proceed to install
- Go to GCP console and disable unused ingress ports that maybe open
Reference
Make a swap file and mount it
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon --show
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
#reboot and check if it works
top
Install docker – https://github.com/docker/docker-install
curl https://get.docker.com > install-docker.sh
cat install-docker.sh
chmod 755 install-docker.sh
sudo ./install-docker.sh
sudo usermod -aG docker <gcp-username>
docker container ls
Install docker-compose – https://docs.docker.com/compose/install/
Download a suitable pre-built container package
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname
-m` -o /usr/local/bin/docker-compose
sudo chmod 755 /usr/local/bin/docker-compose
docker-compose version
sudo apt install git
git clone https://github.com/<find-a-container-package-that-suits-you>.git
Compose and start container
# to build
docker-compose up -d
# to list
docker container ls
# to start all components
docker-compose start
# to verify if all processes have started
docker container ps
# to stop
docker-compose stop
Shutdown and cleanup
# removes containers and default network, but preserves your database
docker-compose down
# removes containers, default network, and the database
docker-compose down --volumes
Conclusion
The experience has been wonderful! Before it used to take me a good part of a weekend to stand up a LAMP stack. I couldn’t believe it literally took me 15 minutes to have a working web application running with a valid SSL and everything! No wonder devs love this so much.
When I have spend decent amount of time with dockers, I’d like to do the same exercise with Kubernetes.
Tags: Blog Cloud Compute Container Docker GCP Hosting Wordpress