Setting up the customizable site "online store"
The download and installation of the "online store" application, as well as the PostgreSQL database necessary for the application's operation, occurs automatically by launching the docker-compose.yml file. For the docker-compose.yml file to work, the Docker and Docker-Compose services must be configured. The configuration of the Docker and Docker-Compose services was discussed in the previous step:
Preparing the operating system for application deployment
Step 1 — Creating the docker-compose.yml file
First, in the root folder of the Ubuntu 20.04 operating system, we create a new folder where we will store our installation file docker-compose.yml:
mkdir mytemp
With this command, we created a new folder mytemp, now let's enter this folder:
cd mytemp
Now let's create our file docker-compose.yml in the mytemp folder:
sudo nano docker-compose.yml
The command 'nano docker-compose.yml' will check if the file docker-compose.yml exists; if it does, it will open it for editing, and if it doesn't, it will create and open it for editing.
In the created and opened file docker-compose.yml, you need to insert the following content:
version: '3.4'
networks:
net_internetshop:
driver: bridge
services:
internetshop:
image: c3poshop/internetshop:latest
depends_on:
- "app_db_internetshop"
container_name: internetshop
ports:
- "5000:80"
environment:
- ConnectionStrings__ConnectionTb=User ID=postgres;Password=YourPassword;Server=app_db_internetshop;Port=5432;Database=aishop;Pooling=true;
- ASPNETCORE_URLS=http://+:80
restart: always
networks:
- net_internetshop
app_db_internetshop:
image: postgres:latest
container_name: app_postgres_internetshop
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=YourPassword
- POSTGRES_DB=aishop
ports:
- "5432:5432"
restart: always
volumes:
- data_internetshop:/var/lib/postgresql/data
networks:
- net_internetshop
volumes:
data_internetshop:
After inserting the above code into the text file docker-compose.yml, to save the file you need to press Ctrl + O then Enter. To exit the editor, you need to press Ctrl + X.
To check for the existence of the created file, type the command ls or ll to view all files in the folder:
ls
If the file is created, it should display:
docker-compose.yml
After the docker-compose.yml file is created and filled out, you need to change several values in it to your confidential data. Open the docker-compose.yml file for editing with the command:
sudo nano docker-compose.yml
Using the arrow keys on the keyboard, you need to sequentially navigate to the 2 positions where 'YourPassword' is located and replace that word with your database password. In both positions, the password must be the same and secure; this is the password for connecting to the database:
- ConnectionStrings__ConnectionTb=User ID=postgres;Password=YourPassword;Server=app_db_internetshop;Port=5432;Database=aishop;Integrated Security=true;Pooling=true;
- POSTGRES_PASSWORD=YourPassword
YourPassword Change to your password. The password in both places must be the same and secure!
After changing the password to your own, save the docker-compose.yml by pressing the key combination Ctrl + O, then Enter. To exit the editor, press Ctrl + X.
Now you can run the docker-compose.yml with the command:
sudo docker compose up -d
If the docker-compose.yml file is filled out correctly, the web application "online store" will be automatically downloaded, as well as the PostgreSQL database, and the data relationship between them will be configured. You should see the process of downloading the application's and database's Docker containers, and at the end, you should see a successful launch of the containers:
✔ Container app_postgres_internetshop Started
✔ Container internetshop Started
It should be noted that the docker-compose.yml file is sensitive to indentation; if the indentations in the text file are incorrect, an error message will appear, indicating the line number where the indentations are incorrect:
yaml: line 19: mapping values are not allowed in this context
If such a message appears, you need to reopen the docker-compose.yml file for editing and correct the indentations at the specified line number until the docker-compose.yml runs successfully!
In case of successful execution of the command sudo docker compose up -d, you can proceed to directly test the application by entering the following address in the browser of the same computer where the application was installed:
http://localhost:5000/
You can run the web application on another computer in the same network by knowing the IP address of the computer where the application was deployed, to find out the IP address, you need to execute the command:
hostname -I
After executing the command hostname -I, a list of IP addresses of your computer will appear, the first one should be the primary:
192.168.64.128 172.17.0.1 172.19.0.1 172.20.0.1 172.18.0.1
-The number of IP addresses and their values may be different for you.
Knowing the IP address of the computer where the application was deployed, you can launch this application from a browser on another computer that can see this IP address by entering the following address in the browser:
http://192.168.64.128:5000
192.168.64.128 - IP address obtained by the command hostname -I
Step 2 — Making changes to docker-compose.yml
If you need to make changes to the docker-compose.yml file, you must first stop the containers that are running through it with the command:
sudo docker compose stop
It should be noted that the commands 'sudo docker compose up -d' and 'sudo docker compose stop' must be executed from the directory where this file is located! That is, you need to physically be in the directory where the docker-compose.yml file was created.
After stopping docker compose, you can proceed to edit the docker-compose.yml file with the command:
sudo nano docker-compose.yml
For example, if you want the application to be visible on port 5000 only within the computer where it was deployed, and not visible externally. For example, if you are configuring a proxy server, you can change the following value in docker-compose.yml:
- "5000:80" needs to be replaced with - "127.0.0.1:5000:80"
Step 3 — Configuring global application usage on the internet
The above steps help deploy the application for local testing to determine whether this application is suitable for you or not. If you want to continue using this application, you will need to configure the Nginx proxy server to bind your domain to the application and set up an HTTPS encrypted connection:
Configuring the Nginx proxy server