Blog

How to Deploy Odoo on a Linux Server Using Docker: A Step-by-Step Guide

Odoo

When I was first introduced to Odoo, I downloaded the book <<Odoo 15 Development Essentials – Fifth Edition>> by Daniel Reis to learn how to develop for Odoo. This book has fifty chapters and I must be ready to work in Odoo in less than two weeks. My mentor asked me to only read the first four chapters to have the key concepts of Odoo and it would be suitable for the work and guess what, he was right. For the eleven remaining chapters, I must read them only when having a specific task to accomplish.

The second essential skill I must acquire quickly on Odoo was to deploy Odoo CE in production on a Linux server and set up an SSL certificate. The tutorial from Linuxize helped me a lot; even today, I used it when deploying Odoo on a Linux server.

Why am I writing this tutorial?

When deploying Odoo with Docker behind a reverse proxy in some of my servers, the Linuxize tutorial doesn’t cover my needs. I searched a lot on the internet to be able to deploy Odoo well with Docker so I decided to write a simple tutorial to explain the process I used to figure it out.

Prerequisite

To follow me along with this tutorial, you need to have access to a Linux server with Docker and docker-compose installed. I have written a tutorial on how to install Docker and docker-compose on a Ubuntu server.

You can practice this tutorial on DigitalOcean Droplet with 200$ free credits for 60 days. All you need to do is to create a small droplet (Linux Server) there and you are ready. Now let’s focus on the tutorial.

1. Odoo without a domain name

Login to your Linux server and create a new directory called odoo for our new Odoo installation. Inside that folder, create a file called docker-compose.yml and paste in the following content:

docker-compose.yml

version: '3.9'

services:
    odoo:
        container_name: odoo
        image: odoo:16.0
        volumes:
            - ./extra-addons:/mnt/extra-addons
            - ./etc/odoo:/etc/odoo
            - odoo-web-data:/var/lib/odoo
        ports:
            - 8069:8069
        depends_on:
            - postgres

    postgres:
        image: postgres:15
        environment:
            - POSTGRES_DB=postgres
            - POSTGRES_PASSWORD=password
            - POSTGRES_USER=odoo
            - PGDATA=/var/lib/postgresql/data/pgdata
        volumes:
            - odoo-db-data:/var/lib/postgresql/data/pgdata

volumes:
    odoo-web-data:
    odoo-db-data:

This docker-compose file has two services and two volumes and is organized as follows:

1.1. The odoo service

In this service,

  • we indicate the version of Odoo we want to use. Note that every year, a new version of Odoo is released during Odoo Experience Event roughly in November.
  • We bind the host volume extra-addons to /mnt/extra-addons inside the container. The extra-addons folder is where we will put all our custom modules. Don’t forget to create that folder in the same directory where we have our docker-compose.yml file, in our case the directory odoo.
  • We create the folder etc/odoo inside the same folder as the docker-compose.yml file and bind that folder to the directory /etc/odoo inside the container. The etc/odoo in the host machine is where we’ll store all the odoo configuration files like odoo.conf.
  • Finally, for this service, we bind the name volume odoo-web-data to /var/lib/odoo to store the data of this odoo instance.

In the folder /etc/odoo we created earlier, create a new file inside and paste the following content:

odoo.conf

[options]
addons_path = /mnt/extra-addons,
admin_passwd = admin_password
db_host = postgres
db_user = odoo
db_password = password

The content of this file is used to configure our odoo installation.

  • addons_path is the same path we put in our docker-compose.yml file. It tells the odoo system where to find custom add-ons. If you have multiple places where you store your custom add-ons, you can list them here and separate them with a comma(“,“)
  • admin_passwd is the master password of the odoo installation. Keep it secure and secret. It’s used to perform various operations like creating a new database and deleting or backup databases.
  • db_host, db_user, and db_password are the same information available in the Postgres service and tell the odoo system how to connect to the database.

1.2. The Postgres service

As you know, Odoo only supports Postgres as RDBMS. Here you can choose the version of Postgres you want to use. The remaining elements are trivial.

1.3. Launch Odoo

At this step, we’re good to launch our odoo instance. Just run the command:

docker compose up

And navigate to http://<YOUR_IP_ADDRESS>:8069 to create a new database.

The first launch of Odoo

The first launch of Odoo

You know how to deploy Odoo in a Linux server using docker. But that is not all. Of course, in a serious business, you can’t work with the IP address or send an IP to your employees to access your ERP. You need a custom and secure domain name for your Odoo instance and that is the point of the next section.

2. Secure your Odoo instance with a domain name and SSL certificate

As far as I am concerned, the easiest and best way is to run Odoo behind a reverse proxy server like Traefik, caddyserver, nginx-proxy manager, and Nginx-proxy. For this tutorial, I would use Nginx-proxy. as the reverse proxy.

2.1. Installation of Nginx-proxy and acme-compagnon

Nginx proxy is a container running Nginx and docker-gen which is a service that generates reverse proxy configs for Nginx and reloads Nginx when containers are started or stopped.

This container is mounted on a docker socket to capture all events created by docker to be able to proxied any container with an env variable VIRTUAL_HOST defined. All containers that want to be proxied by Nginx-proxy must be connected to the same network. To know more about Nginx-proxy, visit the GitHub of the project.

ACME-compagnon is a compagnon for Nginx-proxy responsible to automate the creation, renewal, and use of SSL certificates for proxied Docker containers through ACME protocol. For more information about acme-compagnon, visit the GitHub of the project.

I have a ready-to-use template for Nginx-proxy in my Gitlab repository. You need to clone and run it. This configuration is well-suited for a production environment. Just type the following command in your terminal to make it run in less than a minute.

cd ~
git clone https://gitlab.com/tderick/nginx-proxy-conf.git 
docker network create nginx-proxy
cd nginx-proxy-conf
docker compose up --build -d

For the following part, you need to have a domain name pointing to your server. In this tutorial, I’ll use the subdomain odoo.temfack.com.

2.2. New configs

The new config files are the following.

default.conf

#odoo server
upstream odoo {
  server odoo:8069;
}
upstream odoochat {
  server odoo:8072;
}

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
  listen [::]:80;
  listen 80;

  client_max_body_size 200M;

  server_name erp.ysda2014.org;
  proxy_read_timeout 720s;
  proxy_connect_timeout 720s;
  proxy_send_timeout 720s;

  # Add Headers for odoo proxy mode
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_set_header X-Real-IP $remote_addr;

  # log
  access_log /var/log/nginx/odoo.access.log;
  error_log /var/log/nginx/odoo.error.log;

  # Redirect websocket requests to odoo gevent port
  location /websocket {
    proxy_pass http://odoochat;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
  }

  # Redirect requests to odoo backend server
  location / {
    proxy_redirect off;
    proxy_pass http://odoo;
  }

     # Cache static files
    location ~* /web/static/ {
        proxy_cache_valid 200 90m;
        proxy_buffering on;
        expires 864000;
        proxy_pass http://odoo;
    }

  # common gzip
  gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
  gzip on;
}

docker-compose.yml

version: '3.9'

services:
    odoo:
        container_name: odoo
        image: odoo:16.0
        volumes:
            - ./extra-addons:/mnt/extra-addons
            - ./etc/odoo:/etc/odoo
            - odoo-web-data:/var/lib/odoo
        depends_on:
            - postgres

    postgres:
        image: postgres:15
        environment:
            - POSTGRES_DB=postgres
            - POSTGRES_PASSWORD=password
            - POSTGRES_USER=odoo
            - PGDATA=/var/lib/postgresql/data/pgdata
        volumes:
            - odoo-db-data:/var/lib/postgresql/data/pgdata

    nginx:
        image: nginx:latest
        restart: unless-stopped
        environment:
            - VIRTUAL_HOST=odoo.temfack.com
            - LETSENCRYPT_HOST=odoo.temfack.com
            - LETSENCRYPT_EMAIL=temfack@gmail.com
        volumes:
            - ./nginx/conf:/etc/nginx/conf.d
        depends_on:
            - odoo

volumes:
    odoo-web-data:
    odoo-db-data:

#Use this configuration in production with nginx-proxy container
networks:
  default:
    external: true
    name: nginx-proxy

odoo.conf

[options]
addons_path = /mnt/extra-addons,
admin_passwd = admin_password
db_host = postgres
db_user = odoo
db_password = password

proxy_mode = True

In the docker-compose file, we have added an Nginx service. The purpose of Nginx here is to serve static content. The important thing to notice in this service is where we bind the Nginx configuration file. You should create the folder nginx/conf in the same folder as the docker-compose.yml file and inside that folder create a file called default.conf and paste in the content of default.conf found in the above gist.

As we used Nginx-proxy, specify your domain name in the environment and the email that would be used to issue your free SSL certificate from Let’s Encrypt. Don’t forget to add proxy_mode=True in the odoo.conf because we have to deploy odoo now behind a reverse proxy.

Run the command:

docker compose up --build --force-recreate

and open your domain name to look at the result.

odoo view

The final result

3. Enable Multi-processing

Odoo operates in multithreading mode as a default setting, but for optimal system stability and resource utilization, it is advisable to switch to the multiprocessing server during production deployments. To activate multiprocessing, it is necessary to adjust the Odoo configuration and specify the number of worker processes as a non-zero value. The number of workers is determined by the available CPU cores and RAM of the system. To learn more about the value to add to the odoo.conf, check the official documentation.

Wrap up

In this tutorial, I shared how I deploy Odoo in production with Docker. If one of the steps is not clear to you, write to me and I will correct it.