The Deployment Of an Odoo Web App Using Docker-Compose With a Persistent AWS RDS PostgreSQL Database.
REASONS FOR AN EXTERNAL PERSISTENT DATABASE.
An external persistent database is essential for our Odoo web application to ensure data durability and consistency. Using a persistent PostgreSQL database with Docker Compose, we can maintain data integrity across container restarts and deployments. This setup ensures that critical business information, user data, and application configurations are stored reliably and remain accessible, even if the application containers are recreated or scaled. Additionally, an external database provides better performance, scalability, and easier backup and recovery options, supporting the overall stability and efficiency of our application.
CREATING THE AWS RDS (POSTGRESQL ) DATABASE
Sign in to your AWS Console, Search for RDS, and Click on it. AWS WEBSITE
Click on Database and on the Create Database Button.
Choose a database creation method by picking the standard to create and PostgreSQL Engine options.
You can go with the default Engine version and click on Free-Tier Template.
Configure the settings by clicking credentials settings (choose self-managed) and fill in the master username and password. You can go with the default DB Instance identifier.
Configure Instance configuration settings by choosing the Burstable class and storage type (General Purpose SSD (gp2)).
To Configure Connectivity: Click on Don’t connect to EC2 Instance and choose a VPC (Connectivity for the database must be set to public to connect to it (YES)).
For the VPC security group (firewall), Create a security group with the following port opened and choose the newly created security group.
PORT TYPE | PORT RANGE | SOURCE |
SSH | 22 | Known IP Address Only |
CUSTOM TCP | 8069 | Known IP Address Only |
PostgreSQL | 5432 | Known IP Address Only |
- Leave all other settings as default and Click on the Create Database button.
After creating the database instance, create an EC2 Instance to Install the Odoo docker image using the docker-compose yaml file.
CREATING THE AWS EC2 INSTANCE TO INSTALL ODOO.
STEP 1: LAUNCH AND CONFIGURE AN UBUNTU 22.04 INSTANCE.
Navigate to the EC2 Dashboard and Click on Launch Instance.
Name your server (e.g. Odoo-server).
Choose the Amazon Machine Image. (A lower version would be better because they are more stable). Ubuntu 22.04 for this project.
Choose Instance type (t2.medium would be sufficient) and Key-Pair.
Configure network settings: Use the security group created earlier.
Leave all other settings as default. Then, Click on Launch Instance and the server should be running in a few minutes.
STEP 2: CONNECT TO THE EC2 INSTANCE.
To connect to your server, you would need a SSH client.
I would be using MobaXterm to access my Ubuntu 22.04 EC2 Instance. (You can use any SSH client of your choice).DOWNLOAD MOBAXTERM
To access your server using Mobaxterm you would need some credentials e.g.
Public IPv4 Address from AWS Console.
Private Key (.pem) on your Local computer.
Server Name (ubuntu) for Ubuntu 22.04 Server.
STEP 3: UPDATE THE SYSTEM AND INSTALL DOCKER
Update packages in the apt repo.
sudo apt update -y && sudo apt upgrade -y
Create a docker script to automate the installation of the docker.
sudo vim docker.sh
and paste these commands.
# Add Docker's official GPG key:
sudo apt-get update -y
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Make the docker script executable using this command.
sudo chmod +x docker.sh
Run the docker script
./docker.sh
and check the version of dockerdocker --version
STEP 4: INSTALLING DOCKER-COMPOSE
- Create a docker-compose yaml file to automate the installation of docker-compose
sudo vim docker-compose.sh
and paste these commands
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
Make docker-compose file, script executable.
sudo chmod +x docker-compose.sh
Run the docker-compose script.
./docker-compose.sh
and check the version of docker-compose.docker-compose -v
Run this command to allow admin privileges for the current user (ubuntu).
sudo chmod 666 /var/run/docker.sock
STEP 5: INSTALLING ODOO AND CONNECTING TO THE POSTGRESQL DATABASE USING DOCKER-COMPOSE
Create a directory named Odoo and change the directory to Odoo.
mkdir ~/odoo cd ~/odoo
Create a docker-compose .yml file to automate the provisioning of the Odoo container and the connection to the PostgreSQL database.
sudo vim docker-compose.yml
Paste the following details and edit the database credentials to match the database you created.
version: '3.3'
services:
odoo:
container_name: odoo15
image: odoohost/odoo
# build:
restart: always
tty: true
networks:
- default
ports:
- "0.0.0.0:8069:8069"
volumes:
- odoo-data:/var/lib/odoo:delegated
- ~/odoo15e/enterprise:/mnt/enterprise:delegated
- ~/odoo15e/design-themes:/mnt/design-themes:delegated
- ./conf:/etc/odoo
environment:
- DB_PORT_5432_TCP_ADDR=database-1.cxsgsoio4nkz.us-east-1.rds.amazonaws.com #Insert your Database Endpoint.
- DB_PORT_5432_TCP_PORT=5432 #Default port for PostgreSQL database
- DB_ENV_POSTGRES_USER=MyOdoo #Insert your Database Username
- DB_ENV_POSTGRES_PASSWORD=admin12345 #Insert your Database Password
networks:
default:
driver: bridge
volumes:
odoo-data:
Confirm the docker-compose file is configured correctly.
docker-compose config
Spin up the Odoo container and connect to the PostgreSQL database with the docker-compose command.
docker-compose up -d
STEP 6: ACCESS ODOO ON YOUR BROWSER
- Access Odoo UI from the browser.
http://ipaddress:8069
- Login to Odoo’s Website by filling in the necessary details and Click Create database button.
- To stop the Odoo container.
docker-compose stop
Thank You for following through to the end, I hope you were able to DEPLOY AN ODOO WEB APP USING DOCKER-COMPOSE WITH A PERSISTENT POSTGRESQL DATABASE.
Subscribe to my newsletter
Read articles from TOLANI AKINTAYO directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
TOLANI AKINTAYO
TOLANI AKINTAYO
Cloud DevOps Engineer • DevOps Advocate • (Docker, Kubernetes, CI-CD Automation, Infrastructure as Code, Ansible, Scripting (Bash & Python), Cloud Platforms - AWS) • Technical Writer • Mentor