Vaibhav Singh

Blog - vaibhavsingh.com

A blog inside a container

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

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:

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top