I am familiar with the concept of virtual machines, but have never really liked the concept for a home lab setup. For commercial and business deployments, virtual machines are typically deployed on enterprise servers which are then carved up for a variety of different hosts. A virtual machine can then be clones and migrated to different physical servers fairly easily. However, virtual machines require segregation of hardware, specifically memory and diskspace. In a home lab environment, the resource reservations of the virtual machines can quickly eat up resources even when the services are idle.
To abstract these applications into deployable pieces, I am containerizing my code into Docker containers, which can then be managed through Kubernetes. My first trial at running docker is getting a web site up and running.
changes to /etc/hosts
# Intel NUC7i5BNHG, 32GB RAM
10.0.0.10 nuc00.projectkoios.com nuc00
10.0.0.11 nuc01.projectkoios.com nuc01
10.0.0.12 nuc02.projectkoios.com nuc02
10.0.0.13 nuc03.projectkoios.com nuc03
# Raspberry Pi 4B+ 8GB
10.0.0.20 rpi00.projectkoios.com rpi00
10.0.0.21 rpi01.projectkoios.com rpi01
10.0.0.22 rpi02.projectkoios.com rpi02
10.0.0.23 rpi03.projectkoios.com rpi03
# Nvidia Nano
10.0.0.30 nano00.projectkoios.com nano00
10.0.0.31 nano01.projectkoios.com nano01
10.0.0.32 nano02.projectkoios.com nano02
10.0.0.33 nano03.projectkoios.com nano03
Docker is a software containerization platform in which different applications plus their libraries and dependencies run in separate containers.
Docker Compose is a tool for defining and running multi-container Docker applications. This is possible with a YAML file that is used to configure the application’s services. These services are then created and started with just a single command from the configuration.
Since Docker uses kernel namespaces, the installation on Linux is fairly straight forward. I am interested in having a development system on both my Mac OSX laptop as well as my Windows 10 desktop. However, these instructions apply to Ubuntu 20.8 LTS
To install these pieces of software, we should first update the operating system.
$ sudo apt-get update && sudo apt-get upgrade -y
Then we can install the Docker application
$ sudo apt-get install docker.io -y
Install install docker-compose
$ sudo apt-get install docker-compose -y
We can check to see if Docker and Docker compose are installed by issuing the following commands:
$ docker -v
Docker version 20.10.2, build 20.10.2-0ubuntu1~20.04.2
$ docker-compose -v
docker-compose version 1.25.0, build unknown
Creating a Docker Compose Project
Dockerfile
# syntax=docker/dockerfile:1
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
requirements.txt
#requirements.txt
Django>3,<4.0
psycopg2-binary>=2.8
djangorestframework==3.9.1
gunicorn>=20,<21.0
psycopg2==2.7.7
docker-compose.yaml
version: "3.9"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
References:
[1] Schlosser, Harmut. "Docker vs. Virtual Machine: Where are the differences?" DevOpsCon. https://devopscon.io/blog/docker/docker-vs-virtual-machine-where-are-the-differences/
[2] Vaati, Esther. "Build and Deploy a Django Application using Docker and Compose" https://levelup.gitconnected.com/build-and-deploy-a-django-application-using-docker-and-compose-9bf0d8dc5ebb
[3] Janetakis, Nick "Docker Tip #76: Where to Put Docker Compose Projects on a Server?" https://nickjanetakis.com/blog/docker-tip-76-where-to-put-docker-compose-projects-on-a-server
[3] https://djangodeployment.readthedocs.io/en/latest/