How to Set Up Odoo using Docker and Docker Compose in Ubuntu

Odoo is a framework and a suite of open source business applications including CRM, e-commerce, accounting, manufacturing, warehouse, and inventory management to name a few. It is fully customizable to every business need because its extensible architecture allows developers to modify existing applications and create new applications. I have ample experience solving business needs from small clients to larger enterprises using the Odoo framework. In this guide, I will share my personal development environment and help you create your own local development server for Odoo 16 utilizing Docker.

In this guide we will learn how to set up odoo 16 using postgres 15 in docker.

# Prerequisites

To follow this guide, you will need:

  • An OS with docker installed and running
  • Docker compose installed

# Installing Docker

To begin, we must first have Docker Engine and Docker Compose installed on our system. The installation will vary depending on what platform you’re on and detailed instructions for your platform can be found from the official Docker documentation. Here, I will share the installation process on Ubuntu 22.04:

# Uninstall Old Docker Versions

To make sure your system has no conflicting versions installed, it is a good idea to first run this command to uninstall them:

1
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

# Set Up Docker Repository

In order to get the latest Docker packages, we are using the official Docker repository.

Let’s first update the apt package index and install the prerequisite packages:

1
2
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

Next, we add the official Docker GPG key to ensure authenticity and security of our Docker packages:

1
2
3
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Lastly, the following command will set up the repository:

1
2
3
4
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker Engine

Now that the repository is all set up. We just need to update our package index and install the necessary Docker packages:

1
2
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Start and enable Docker

1
2
sudo systemctl start docker
sudo systemctl enable docker

Add the current user to docker group

1
sudo usermod -aG docker $USER

Check if Docker is running:

1
sudo systemctl status docker

# Installing Docker Compose

If you are running ubuntu, use the following command to install docker-compose.

1
2
sudo apt update
sudo apt install docker-compose

Once installed, confirm that it is running as expected by checking the version:

1
2
3
4
5
6
$ docker-compose version

docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.1k  FIPS 25 Mar 2021

# Setting up odoo in Docker

Odoo requires a running PostgreSQL server.

Start a PostgreSQL server using this command:

1
2
3
4
5
6
docker run -d \
    -e POSTGRES_USER=odoo \
    -e POSTGRES_PASSWORD=odoo \
    -e POSTGRES_DB=postgres \
    --name postgres \
    postgres:15-alpine

Start an Odoo instance

1
docker run -p 8069:8069 --name odoo --link postgres:postgres -t odoo:16.0

Confirm that they are running with this command:

1
doker ps

The alias of the container running Postgres must be postgres for Odoo to be able to connect to the Postgres server.

Stop and restart an Odoo instance

1
2
docker stop odoo
docker start -a odoo

A more robust way to run odoo and the Postgres and the Odoo server is using docker-compose. Let us examine that in the following section. But first stop and remove the containers.

1
2
3
4
5
docker stop odoo
docker stop postgres

docker rm -f odoo
docker rm -f postgres

# Running Odoo using docker-compose

To get started creating your Odoo and PostgreSQL containers, create a directory called odoo in your home directory to store the files that you will create in this tutorial. You’ll use this directory to store all the files that you need to run Odoo.

Run the following commands to create the directory and then cd into it:

1
2
mkdir ~/odoo
cd ~/odoo

Now open a new blank YAML file called docker-compose.yaml using vim or your preferred editor and add the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
version: '3.9'

services:
  odoo:
    image: odoo:16.0
    restart: always
    depends_on:
    - postgres
    environment:
    - HOST=postgres
    - USER=odoo
    - PASSWORD=odoo
    volumes:
      - odoo_data:/var/lib/odoo
    ports:
    - 8069:8069
    networks:
    - odoo_net

  postgres:
    image: postgres:15-alpine
    restart: always
    volumes:
    - odoo_pgdb:/var/lib/postgresql/data
    environment:
    - POSTGRES_DB=postgres
    - POSTGRES_PASSWORD=odoo
    - POSTGRES_USER=odoo
    networks:
    - odoo_net

volumes:
  odoo_pgdb:
  odoo_data:

networks:
  odoo_net:

The file defines two services. The first is called odoo, which runs the Odoo application. The second is called postgres, which is the PostgreSQL database container. Both services reference named volumes that they use to store data outside of the running container instances. Finally, the odoo service exposes port 8069 on your server to the Odoo container that is running on the same port 8069.

We also have some environment variables defined that dictate connection settings to the database. I am using odoo as the password but you should consider a strong password.

To generate a password for Odoo and PostgreSQL, use the openssl command, which should be available on most Linux systems. Run the following command on your server to generate a random set of bytes and print a base64 encoded version that you can use as a password:

1
openssl rand -base64 30

Save and exit the file when you are done editing it.

You’re now ready to start the odoo and postgres containers with the docker-compose command:

1
docker-compose up -d

The up sub-command tells docker-compose to start the containers and the associated volumes and networks that are defined in the docker-compose.yaml file. The -d flag (which stands for daemonize) tells docker-compose to run the containers in the background so the command doesn’t take over your terminal. docker-compose will print some brief output as it downloads the required Docker images and then starts the containers:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ docker-compose up -d

Creating network "odoo_odoo_net" with the default driver
Creating volume "odoo_odoo_pgdb" with default driver
Creating volume "odoo_odoo_data" with default driver
Pulling postgres (postgres:15-alpine)...
15-alpine: Pulling from library/postgres
...
Status: Downloaded newer image for odoo:16.0
Pulling odoo (odoo:16.0)...
16.0: Pulling from library/odoo
...
Creating odoo_postgres_1 ... done
Creating odoo_odoo_1     ... done```

Confirm that the services are running

1
2
3
4
5
$ docker-compose ps
     Name                    Command              State                              Ports
----------------------------------------------------------------------------------------------------------------------
odoo_odoo_1       /entrypoint.sh odoo             Up      0.0.0.0:8069->8069/tcp,:::8069->8069/tcp, 8071/tcp, 8072/tcp
odoo_postgres_1   docker-entrypoint.sh postgres   Up      5432/tcp

When that’s done, Odoo should be running. You can test that a webserver is running at 127.0.0.1:8069 by fetching the homepage using the curl command:

1
curl --head http://localhost:8069

This will print out only the HTTP headers from the response:

1
2
3
4
5
6
7
HTTP/1.0 303 SEE OTHER
Content-Type: text/html; charset=utf-8
Content-Length: 215
Location: http://localhost:8069/web
Set-Cookie: session_id=2ac13bac5c10d6fce7b432eef69ab48e6beb759a; Expires=Mon, 11-Sep-2023 18:42:09 GMT; Max-Age=604800; HttpOnly; Path=/
Server: Werkzeug/1.0.1 Python/3.9.2
Date: Mon, 04 Sep 2023 18:42:09 GMT

The 303 SEE OTHER response means the Odoo server is up and running, but that you should visit another page to complete the installation. The highlighted http://localhost:8069/web Location header indicates where to visit the Odoo installer page in your browser.

Next we’ll set up Nginx to proxy public traffic to the Odoo container.

# Setting up Nginx as a proxy server

Putting a web server such as Nginx in front of your Odoo server can improve performance by offloading caching, compression, and static file serving to a more efficient process. We’re going to install Nginx and configure it to reverse proxy requests to Odoo, meaning it will take care of handing requests from your users to Odoo and back again. Using a non-containerized Nginx process will also make it easier to add Let’s Encrypt TLS certificates in the next step.

First, refresh your package list, then install Nginx using apt:

1
2
sudo apt update
sudo apt install nginx

Next, open up a new Nginx configuration file in the /etc/nginx/conf.d directory. We’ll call ours odoo.conf but you could use a different name:

1
sudo nano /etc/nginx/conf.d/odoo.conf

Paste the following into the new configuration file, being sure to replace your_domain_here with the domain that you’ve configured to point to your Odoo server. This should be something like odoo.citizix.com, for instance:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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;
  }
}

This configuration is HTTP-only for now, as we’ll let Certbot take care of configuring TLS in the next step. The rest of the configuration file sets up logging locations and then passes all traffic, as well as some important proxy headers, along to http://localhost:8069, the Odoo container that we started up in the previous step.

Save and close the file.

Use nginx -t to verify that the configuration file syntax is correct:

1
2
3
4
$ sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

And finally, reload the nginx service with the new configuration:

1
sudo systemctl reload nginx

Your Odoo site should now be available on plain HTTP. Load http://your_domain_here (you may have to click through a security warning) and you will get odoo landing configuration page.

Now that you have your site up and running over HTTP, it’s time to secure the connection with Certbot and Let’s Encrypt certificates. You should do this before going through Odoo’s web-based setup procedure.

# Setting up TLS with Certbot

Next, run certbot in --nginx mode, and specify the same domain that you used in the Nginx server_name configuration directive:

1
sudo certbot --nginx -d your_domain_here

You’ll be prompted to agree to the Let’s Encrypt terms of service, and to enter an email address.

Afterwards, you’ll be asked if you want to redirect all HTTP traffic to HTTPS. It’s up to you, but this is generally recommended and safe to do.

After that, Let’s Encrypt will confirm your request and Certbot will download your certificate.

Certbot will automatically reload Nginx with the new configuration and certificates. Reload your site in your browser and it should switch you over to HTTPS automatically if you chose the redirect option.

Your site is now secure and it’s safe to continue with the web-based setup steps.

# Setting up

Back in your web browser, reload the page. You should now have Odoo’s database configuration page open via a secure https:// connection. Now you can enter usernames and passwords safely to complete the installation process.

The information that you fill in on this page will tell the Odoo application how to create its PostgreSQL database and details about the default administrative user.

Once you fill them you should be able to configure and use your odoo set up.

# Conclusion

In this tutorial, you launched the Odoo ERP app and a PostgreSQL database using Docker Compose, then set up an Nginx reverse proxy and secured it using Let’s Encrypt TLS certificates.

You’re now ready to start building your ERP website using the supplied modules. For more information about using Odoo please see the official Odoo documentation.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy