Step-by-Step Guide for Installing Odoo with Docker Compose and Nginx
Step 1: Installing Docker Compose
To set up Odoo using Docker Compose, follow these steps:
Update Your Package List:
sudo apt update
Install Docker Compose:
sudo apt install docker-compose
Note: If you prefer a more recent Docker Compose package than the one included with Ubuntu 20.04, please refer to Step 1 of the guide titled "How To Install and Use Docker Compose on Ubuntu 20.04." If you choose to use this version, replace the "docker-compose" command with "docker-compose."
Verify the Installation:
docker-compose --version
You should see output similar to this:
docker-compose version 1.25.0, build unknown docker-py version: 4.1.0 CPython version: 3.8.10
Once Docker Compose is installed, proceed to the next step to configure and launch Odoo and PostgreSQL containers.
Step 2: Running Odoo and PostgreSQL with Docker Compose
To create Odoo and PostgreSQL containers, follow these steps:
Create a Directory for Odoo Files:
mkdir ~/odoo cd ~/odoo
Create a Docker Compose Configuration File:
nano docker-compose.yml
Add the Following Content to "docker-compose.yml":
version: '3'
services:
odoo:
image: odoo:16.0
env_file: .env
depends_on:
- postgres
ports:
- "127.0.0.1:8069:8069"
volumes:
- data:/var/lib/odoo
postgres:
image: postgres:15
env_file: .env
volumes:
- db:/var/lib/postgresql/data/pgdata
volumes:
data:
db:
Save and Exit the File.
Create an Environment File for Configuration:
nano .env
Add the Following Content to ".env," Replacing the Highlighted Values with Your Desired Values:
# PostgreSQL environment variables
POSTGRES_DB=postgres
POSTGRES_PASSWORD=a_strong_password_for_user
POSTGRES_USER=odoo
PGDATA=/var/lib/postgresql/data/pgdata
# Odoo environment variables
HOST=postgres
USER=odoo
PASSWORD=a_strong_password_for_user
Generate Strong Passwords for Odoo and PostgreSQL Using the openssl Command and Replace the "a_strong_password_for_user" Placeholders in the ".env" File.
Save and Exit the ".env" File.
Start the Odoo and PostgreSQL Containers in the Background:
docker-compose up -d
Docker Compose Will Download the Necessary Docker Images and Start the Containers.
To Stop the Containers at Any Time, Run the Following Command in the "~/odoo" Directory:
docker-compose stop
With the containers running, you can test the Odoo server using the following curl command:
curl --head http://localhost:8069
This confirms that the Odoo server is operational. Next, proceed to set up Nginx for proxying public traffic to the Odoo container.
Step 3: Installing and Configuring Nginx
To configure Nginx for reverse proxying, follow these steps:
Install Nginx and Allow Public Traffic to Ports 80 and 443:
sudo apt update sudo apt install nginx sudo ufw allow "Nginx Full"
Create an Nginx Configuration File (e.g., "odoo.conf") in the "/etc/nginx/sites-available" Directory:
sudo nano /etc/nginx/sites-available/odoo.conf
Add the Following Configuration to "odoo.conf," Replacing "your_domain_here" with Your Actual Domain Name:
server {
listen 80;
listen [::]:80;
server_name your_domain_here;
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://localhost:8069;
}
}
Save and Close the File.
Enable the Nginx Configuration by Creating a Symbolic Link in the "/etc/nginx/sites-enabled" Directory:
sudo ln -s /etc/nginx/sites-available/odoo.conf /etc/nginx/sites-enabled/
Verify the Nginx Configuration:
sudo nginx -t
Reload Nginx to Apply the New Configuration:
sudo systemctl reload nginx.service
Your Odoo site is now accessible over plain HTTP. Continue to the next step to secure the connection with TLS certificates using Certbot and Let's Encrypt.
Step 4: Installing Certbot and Setting Up TLS Certificates
To add TLS encryption to your Odoo site, follow these steps:
Install Certbot and the Nginx Plugin:
sudo apt install certbot python3-certbot-nginx
Run Certbot in --nginx Mode and Specify Your Domain:
sudo certbot --nginx -d your_domain_here
Agree to the Let's Encrypt Terms, Enter Your Email Address, and Choose Whether to Redirect HTTP Traffic to HTTPS When Prompted.
Certbot Will Automatically Obtain and Configure Your SSL/TLS Certificate and Reload Nginx With the New Configuration.
Your Odoo Site Is Now Secure With HTTPS.
Step 5: Setting Up Odoo
Reload your Odoo site via HTTPS in your web browser. You will be directed to Odoo's database configuration page, where you can enter the necessary information to complete the installation. Fill out the fields as follows:
Database Name: odoo
Email: Your email address
Password: A strong and unique password for the administrator login
Demo data: Check this option if it's your first Odoo installation
Click the "Create database" button, and Odoo will create its database tables. Afterward, you'll be redirected to the Odoo Apps administrative page. Keep a record of the email and password you chose, as they will be used to log in to Odoo in the future. Your Odoo installation is now complete and secured with TLS encryption.
Subscribe to my newsletter
Read articles from Sundar Adhikari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by