Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 39 ยท Deployment and Customisation

Docker, nginx and HTTPS for Odoo

Run Odoo and PostgreSQL with Docker Compose, mount custom addons and config, put nginx in front with HTTPS and websocket routing, and understand volumes, with runnable stand-ins.

Installing Odoo by hand means Python packages, system libraries, wkhtmltopdf, PostgreSQL and a service file. Docker packages all of that: you run an official image for Odoo and another for PostgreSQL, tell them how to talk to each other and keep the data in volumes. This is also the easiest way to give every developer the same environment.

Docker is not available on this site, so every file is read-only. The stand-ins model two jobs that are normally done by the Odoo image and by nginx: turning environment variables into settings, and routing paths to upstream servers.

Docker Compose for Odoo

YAML
services:
  db:
    image: postgres:16
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: odoo
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
    secrets:
      - db_password
    volumes:
      - db-data:/var/lib/postgresql/data
    restart: unless-stopped

  odoo:
    image: odoo:18.0
    depends_on:
      - db
    ports:
      - "127.0.0.1:8069:8069"
      - "127.0.0.1:8072:8072"
    environment:
      HOST: db
      USER: odoo
      PASSWORD_FILE: /run/secrets/db_password
    secrets:
      - db_password
    volumes:
      - odoo-data:/var/lib/odoo
      - ./config:/etc/odoo
      - ./addons:/mnt/extra-addons
    restart: unless-stopped

volumes:
  db-data:
  odoo-data:

secrets:
  db_password:
    file: ./secrets/db_password.txt

What to notice:

  • Two services. The odoo container reaches the database at host name db, the service name, through the Compose network.
  • Volumes. db-data keeps PostgreSQL files and odoo-data keeps Odoo's filestore (attachments and images are files on disk, not database rows). Losing either loses data, so both must be backed up (Backups and Upgrades).
  • Bind mounts. ./config holds your odoo.conf; ./addons is the folder where your custom modules live. The official image already lists /mnt/extra-addons in addons_path.
  • Secrets. Use *_FILE variables and Docker secrets instead of writing passwords in the Compose file.
  • Ports. Bind to 127.0.0.1 so only the reverse proxy on the same machine can reach Odoo; never publish PostgreSQL's port.
  • Pin versions. odoo:18.0 follows a branch. The image is rebuilt nightly, so some teams build their own image from a fixed commit for repeatability.

Typical commands:

Terminal
docker compose up -d                    # start everything in the background
docker compose logs -f odoo             # follow the log
docker compose exec odoo odoo -d mydb -u library --stop-after-init   # update a module
docker compose exec odoo odoo shell -d mydb                          # ORM shell
docker compose down                     # stop (volumes stay)

The nginx reverse proxy

Odoo should not face the internet on its own. nginx adds HTTPS, compression, caching of static files and buffering, and routes websocket traffic to the gevent port.

NGINX
upstream odoo      { server 127.0.0.1:8069; }
upstream odoo_chat { server 127.0.0.1:8072; }

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

server {
    listen 80;
    server_name erp.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name erp.example.com;

    ssl_certificate     /etc/letsencrypt/live/erp.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/erp.example.com/privkey.pem;

    client_max_body_size 100m;
    proxy_read_timeout 720s;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    location /websocket {
        proxy_pass http://odoo_chat;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }

    location / {
        proxy_pass http://odoo;
    }

    gzip on;
    gzip_types text/css application/javascript application/json image/svg+xml;
}

Key points: redirect HTTP to HTTPS; pass the original host and protocol headers (Odoo reads them because proxy_mode = True, see Configuration and Deployment); raise client_max_body_size so uploads work; keep a long proxy_read_timeout for reports and imports. Free certificates come from Let's Encrypt, renewed automatically by Certbot or a similar tool.

flowchart LR
    B["Browser"] -->|"HTTPS 443"| N["nginx"]
    N -->|"/ -> 8069"| O["odoo container"]
    N -->|"/websocket -> 8072"| O
    O --> D[("postgres container")]
    O --> F[("filestore volume")]

Only nginx is public; Odoo and PostgreSQL stay on private ports.

Stand-in: environment variables to configuration

The official image's entrypoint turns the environment into command-line options for Odoo. This stand-in does the same job for a few names. A NAME_FILE variable takes precedence over NAME.

Python Build Odoo options from environment

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Stand-in: path routing like nginx

The second stand-in picks the upstream for a request path using longest-prefix matching, the way nginx chooses a location, and shows the redirect from port 80.

Python Choose an upstream by path prefix

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Development setup

For development, many teams mount the Odoo source code (cloned from GitHub) and run with --dev=all, so edits reload instantly, while the database runs in a container. A docker-compose.override.yml can hold these development-only settings so the production file stays clean.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where does Odoo keep attachments and uploaded images by default?

    The filestore holds binary files. Without a volume, recreating the container would lose them.
  2. 2. Why bind Odoo's ports to 127.0.0.1 in Compose?

    Publishing only on localhost keeps Odoo off the public network; nginx is the only public entry.
  3. 3. Which nginx location should proxy to Odoo's gevent port?

    The live updates connection uses /websocket and needs the Upgrade headers.
  4. 4. How should the database password reach the containers in production?

    Secrets files keep passwords out of the compose file and the git history.

Summary

  • Compose runs Odoo and PostgreSQL as two services with volumes for data and the filestore.
  • Mount config and custom addons; use secrets and pinned image versions.
  • nginx terminates HTTPS, forwards headers, routes /websocket to port 8072 and everything else to 8069.
  • Keep database and Odoo ports private.

Next: Backups and Upgrades