Odoo Docker Setup - Docker Compose

Odoo Docker Setup - Docker Compose

In this article we will cover how you can use docker compose to install odoo on a target machine

Requirements on our end are pretty simple and straight forward

  • Control over configuration
  • Control over custom installed modules
  • Ability to persist data between consecutive runs
  • Ability to monitor logs of critical services (PostgreSQL and Odoo)

Furthermore we will explore how we can

  • Inspect status of running containers
  • Start or stop odoo services
  • Inspect logs of individual services

Lets Code

We start by first creating our base directory odoo-docker-deployment

Within that directory we will create following files and directories

  • .env
  • docker-compose.yml
  • config/odoo.conf
  • addons/

Lets define the first file .env

POSTGRES_PASSWORD=odoo
POSTGRES_USER=odoo

Next add following contents to docker-compose.yaml

version: '2'
services:
  web:
    image: odoo:11.0
    depends_on:
      - db
    ports:
      - "8069:8069"
    volumes:
      - odoo-web-data:/var/lib/odoo
      - ./config:/etc/odoo
      - ./addons:/mnt/extra-addons
  db:
    image: postgres:10
    environment:
      - POSTGRES_PASSWORD
      - POSTGRES_USER
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - odoo-db-data:/var/lib/postgresql/data/pgdata
volumes:
  odoo-web-data:
  odoo-db-data:

Now we will add odoo.conf to config directory

[options]
addons_path = /mnt/extra-addons
data_dir = /var/lib/odoo
; admin_passwd = admin
; csv_internal_sep = ,
; db_maxconn = 64
; db_name = False
; db_template = template1
; dbfilter = .*
; debug_mode = False
; email_from = False
; limit_memory_hard = 2684354560
; limit_memory_soft = 2147483648
; limit_request = 8192
; limit_time_cpu = 60
; limit_time_real = 120
; list_db = True
; log_db = False
; log_handler = [':INFO']
; log_level = info
; logfile = None
; longpolling_port = 8072
; max_cron_threads = 2
; osv_memory_age_limit = 1.0
; osv_memory_count_limit = False
; smtp_password = False
; smtp_port = 25
; smtp_server = localhost
; smtp_ssl = False
; smtp_user = False
; workers = 0
; xmlrpc = True
; xmlrpc_interface = 
; xmlrpc_port = 8069
; xmlrpcs = True
; xmlrpcs_interface = 
; xmlrpcs_port = 8071

At last we will create addons directory which can be use to mount custom addons created by 3rd parties

Managing Odoo Services

In this section we will cover how we can control our docker instance

Starting Services

We can start services using following simple command

docker-compose up -d

-d flag instruct docker compose to run services as deamon

Inspecting Services

We can inspect running services using following command

docker-compose ps

Inspecting Logs

There are many approaches you can take to inspect logs of running services

We will start by most simple and primitive approach

docker-compose logs

Above command will dump logs of all the running services although I have found this command to be seldom useful

We will now cover how we can inspect individual services logs

docker-compose logs [service_name] -f --tail=10

In above command we use -f flag to follow logs and --tail to fetch last 10 lines you can always increase this number to your liking

This gives us following 2 commands to inspect logs of Odoo and PostgreSQL respectively

docker-compose logs web -f --tail=10
docker-compose logs db -f --tail=10

Interacting with Odoo container

We will use the following command to bind our shell to odoo container

docker-compose exec -it web /bin/bash

After shell is bound you can run any command within odoo container enviornment will be pretty much similar to running a remote shell using ssh

Stopping containers

At last we will cover how we can stop all the running services

docker-compose down

If you faced any problem following the tutorial you can refer to carbonteq gitlab repository simply clone the repository and use managing odoo services section for operations.