Step-by-Step Guide for Installing Odoo with Docker Compose and Nginx

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:

  1. Update Your Package List:

     sudo apt update
  2. 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."

  3. 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:

  1. Create a Directory for Odoo Files:

     mkdir ~/odoo
     cd ~/odoo
  2. Create a Docker Compose Configuration File:

     nano docker-compose.yml
  3. Add the Following Content to "docker-compose.yml":

version: '3'
    image: odoo:16.0
    env_file: .env
      - postgres
      - ""
      - data:/var/lib/odoo
    image: postgres:15
    env_file: .env
      - db:/var/lib/postgresql/data/pgdata

  1. Save and Exit the File.

  2. Create an Environment File for Configuration:

     nano .env
  3. Add the Following Content to ".env," Replacing the Highlighted Values with Your Desired Values:

# PostgreSQL environment variables

# Odoo environment variables
  1. Generate Strong Passwords for Odoo and PostgreSQL Using the openssl Command and Replace the "a_strong_password_for_user" Placeholders in the ".env" File.

  2. Save and Exit the ".env" File.

  3. Start the Odoo and PostgreSQL Containers in the Background:

     docker-compose up -d
  4. Docker Compose Will Download the Necessary Docker Images and Start the Containers.

  5. 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:

  1. Install Nginx and Allow Public Traffic to Ports 80 and 443:

     sudo apt update
     sudo apt install nginx
     sudo ufw allow "Nginx Full"
  2. Create an Nginx Configuration File (e.g., "odoo.conf") in the "/etc/nginx/sites-available" Directory:

     sudo nano /etc/nginx/sites-available/odoo.conf
  3. 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;
  1. Save and Close the File.

  2. 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/
  3. Verify the Nginx Configuration:

     sudo nginx -t
  4. 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:

  1. Install Certbot and the Nginx Plugin:

     sudo apt install certbot python3-certbot-nginx
  2. Run Certbot in --nginx Mode and Specify Your Domain:

     sudo certbot --nginx -d your_domain_here
  3. Agree to the Let's Encrypt Terms, Enter Your Email Address, and Choose Whether to Redirect HTTP Traffic to HTTPS When Prompted.

  4. Certbot Will Automatically Obtain and Configure Your SSL/TLS Certificate and Reload Nginx With the New Configuration.

  5. 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.