- Structure of the project
- Installing project using_dockerhub
- Installing project on empty virtual machine
The goal of this project is to describe the procedure for running a simple microservice-oriented project written in Python, along with its frontend written in Angular and Vanilla JS.
The first step is to describe and run the program using docker-compose.
The project described below can be installed without building Docker images, using pre-built images already pushed on DockerHub. To do this, you can follow the steps below:
Create a docker-compose.yaml file with the following content:
services:
db:
restart: always
image: postgres
environment:
- POSTGRES_USER=$POSTGRES_USER
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_DB=$POSTGRES_DB
app:
image: igorjeremic/testapp
environment:
- POSTGRES_HOST=db
- POSTGRES_USER=$POSTGRES_USER
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_DB=$POSTGRES_DB
depends_on:
- db
volumes:
- ./logs:/var/log/app/
nginx:
image: igorjeremic/testnginx
depends_on:
- app
ports:
- $NGINX_EXPOSED_ON:80Create a .env file and populate it with the following information:
NGINX_EXPOSED_ON=8822
POSTGRES_DB=db
POSTGRES_USER=app
POSTGRES_PASSWORD=xyzRun the project by executing the following command in your terminal:
docker compose up -dThis command will start the containers in detached mode, meaning they will run in the background. The PostgreSQL database, the application container, and the Nginx container will be up and running, and the application should be accessible at http://localhost:8822.
- README.md (this file)
- .env.sample (environment sample file, need to be copied and edited)
- Dockerfile.app (instructions for building app image)
- Dockerfile.nginx (instructions for building nginx image)
- docker-compose.yaml (docker compose configuration)
- config/nginx.conf (configuration for nginx)
- app/app.py (backend application)
- web/index.html (web application)
For documentation purposes, I am using DigitalOcean as the VM provider. However, please note that this procedure is almost the same for any other provider. I am also using the latest Ubuntu LTS (at the moment, version 22.04) and providing instructions for Docker installation on this OS. The steps may vary slightly for other Unix systems, but the overall process remains similar.
To create a virtual machine on your DigitalOcean account, follow these steps:
- Sign in to your DigitalOcean account at https://www.digitalocean.com/.
- Once logged in, click on the "Create" button in the top-right corner of the dashboard.
- Select "Droplets" from the dropdown menu.
- In the "Choose an image" section, select "Distributions" tab and choose "Ubuntu 22.04 x64" as the operating system. This is the latest Ubuntu LTS version at the moment.
- In the "Choose a plan" section, select the smallest available machine size. For example, choose the one with 1 CPU, 1 GB RAM, and 25 GB SSD.
- In the "Add backups" and "Add block storage" sections, for this test, you can skip these options.
- In the "Choose a datacenter region" section, select the datacenter region closest to your location or the one that suits your needs.
- Under the "Select additional options" section you can leave default options.
- In the "Authentication" section, choose either an SSH key (if you have one) or a root password to access your virtual machine. SSH key-based authentication is more secure, so if you have an SSH key, it's recommended to use that.
- Finally, give your virtual machine a hostname or leave it as the default.
- Click on the "Create Droplet" button at the bottom of the page to start creating the virtual machine.
- DigitalOcean will now create your virtual machine with the specified configuration. Once the creation process is complete,
- You can then access your virtual machine using SSH (or other methods) and proceed with the rest of the installation and setup for your microservice-oriented project.
for example IP of this machine is aa.bb.cc.dd
ssh root@aa.bb.cc.ddUpdate and upgrade your server to apply latest OS updates
apt update
apt upgradeCreate which will run service (let call him user in this test), add this user to sudoers
adduser user
usermod -a -G sudo userMore details about this installation you can find at
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt-cache policy docker-ce
sudo apt install docker-ce -yusermod -aG docker userDocker compose plugin will be installed on users account
more details about this installation you can find at
su - user
mkdir -p ~/.docker/cli-plugins/Fetch the latest version of Docker Compose to check which version is the most recent. You can visit https://github.com/docker/compose/releases/ to find the latest version. As of now, the latest version is v2.20.2. If a newer version is available, try with the newer one. Simply replace the version in the following CURL request.
curl -SL https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-composeTo make this script executable, use the following command:
chmod +x ~/.docker/cli-plugins/docker-composegit clone https://github.com/digital-cube/docker-test-app.git
cd docker-test-app
setup environments by copying and editing env file
In the .env file, set up the port, username, password, and database name, or leave them as default values.
Remember not to push the .env file to .git as it contains specific installation credentials (this file is .gitignored)
cp .env.sample .envBuild docker images
docker compose buildStart docker images
docker compose up -dfollow logs in logs/app
tail -f logs/app.logyou can find log in logs/app/
also you should be able to access to web application using browser at