Part 12: Preparing Docker Stacks


In this part we will start to prepare the software stacks on Docker environment to run the required services, like Odoo, PostgreSQL, ethereum node, and bitcoin node.


Watch on Youtube    Back to Course Index

Hi. Good morning guys. 

This is your one stop channel to become a full stack blockchain engineer.

This is part 12 of the whole course on how to build a Crypto E-Wallet and Exchange System using Odoo. 

In this part we will start to prepare the software stacks on Docker environment to run the required services, like Odoo, PostgreSQL, ethereum node, and bitcoin node.

Before continuing, please consider to like, share, and subscribe our channel if you find it useful, as we will update the topics of Building E-wallet Exchange system with Odoo regularly.

Ok, now let's talk about the system architecture in details.


What is a docker container? 

Docker is a tool that allows developers to easily deploy and run their applications in a portable container, that can run on any system with Docker installed. This makes it easier to develop and test applications, and to run them in a variety of environments. 

A Docker container is a lightweight, standalone, and executable package of software, that allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

This ensures that the application will run on any other machine regardless of any customized settings that machine might have, that could differ from the machine used for writing and testing the code.

Because a Docker container packages everything an application needs to run, it is very portable and can be easily moved from one system to another.

This makes Docker containers a popular choice for deploying applications in a variety of environments, from local development environments to cloud-based systems.

[docker container in a OS]



What is docker stack? 

Docker stacks are a group of interconnected services that are used to deploy an application. Each service in a Docker stack runs in a separate container, and the containers are all managed by Docker.

Docker stacks are typically used in a production environment, where multiple services need to be deployed and managed together.

Here, we will compose a docker stack configuration file to be able to run some docker container services, which are Odoo, PostgreSQL, and later, Bitcoin Node and Ethereum Node.



Defining the docker-compose.yml

To fulfill the requirements we defined before, at least, we need Odoo and PostgreSQL service stack. We will talk about other software stacks in the next parts.

First, define the service tag on the YAML file, that will contain 2 entries for the services, which are odoo and db services.

Here is the minimum docker-compose.yml file for Odoo and PostgreSQL stack.

services:
  odoo:
    image: odoo:15
    depends_on:
      - db
    ports:
      - "8069:8069"
    volumes:
      - ./config:/etc/odoo:delegated
      - ./addons:/mnt/extra-addons:delegated 
  db:
    image: postgres:12
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_PASSWORD=odoo
      - POSTGRES_USER=odoo
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - ./db-data:/var/lib/postgresql/data/pgdata
    ports:
- "5433:5432"

Save it to a folder and name it docker-compose.yml.

The Odoo Service

The odoo service is defined as follow.

The image tag, is used to define the docker image used for the service. We use my custom docker image for Odoo stack. It is basically a regular Odoo image, but it  includes the required libraries for our application already, like python simplejson, web3, bitcoin rpc, etc.

The service depends on other service called db for the database, that we will define later. We must create a service called db in this case.

Then we expose the service port, which is 8069 in this case. The container itself by default provides access on port 8069 internally, but if we do not expose it, it will not be accessible from outside the container.

Next, we define the volumes needed by Odoo service.

The first volume, the local host folder called config, is mapped to our odoo configuration file to the host running docker, so that it will be persistent on the host file system rather than inside the container.

The second volume, the local host folder called addons, is mapped to our Odoo custom addons to the host, so that when we need to add or upgrade custom addons, we don't have to go inside the container, and it will be persistent on the host drive.

The PostgreSQL Service

Next, we define the database service, the db, which use the standard PostgreSQL docker image.

In this service, we must define the environment variable for the container to run correctly.

The POSTGRES_DB variable is used to the default database name created when we deploy the container.

The POSTGRES_USER variable is used to define the default username to access the database.

The POSTGRES_PASSWORD variable is used to define the default password to access the database.

The PGDATA variable is used to define the folder path for PostgreSQL to store the data to. It is related to the volume definition on the service.

Next, we define the volumes needed by PostgreSQL service. Here, we define that the local host folder db-data is mapped inside the container to a folder called /var/lib/postgresql/data/pgdata. Since this folder is previously set as the PG_DATA environment variable, then PostgreSQL will store its data folder inside this folder, which means it will write the data into the host drive, for data persistency.

Then, we expose the service port, which is 5432 in this case, so that it is accessible from outside the container.

To learn how to create your own custom docker image, you may consult my other courses on Udemy or TutorialsPoint website.

Run the Services Stack

To run the service, just go to the folder containing the docker-compose.yml file we created before, and then execute this command:

docker compose up -d

This will make docker run our defined software stacks.

First it will pull all required images, which are the postgresql and odoo images, if it was not exist yet on our local computer.

When all images are downloaded, it will start to run the services according to our stack definition, like ports to open, volumes to map to the host folder, setting up the environment variables, etc.

Once all services are running correctly, it will go to the background and ready to accept connections to the exposed ports, which are 8069 and 5432, or any other ports that you define on the docker-compose.yml file.



Check the Services Stack

To check whether the containers defined are running or not, we can see them by executing this command.

docker ps

Then, make sure that our 2 services are listed there, along with the correct images we want to run, and the exposed ports are correctly setup.


Testing

Make sure the containers are running, and then test using a browser to your server address, for example http://localhost:8069

You will see the default Odoo database management for us to start creating new database. Try to create one.


After a few moment, you will be inside Odoo blank database without any applications.

Try to install some application, for example, Sale and Invoicing modules.


If the Sale and Invoicing modules are installed correctly without any errors, then we can be sure that our docker stacks are working properly.


Congratulations!

--

Ok, those are the docker stack and services to be deployed to fulfill our software specification.

Please consider to like, share, and subscribe our channel if you find it useful, as we will update the topics of Building E-wallet Exchange system with Odoo regularly.

Thanks for watching.