Run Odoo With Docker

Previously we already tried how to install Odoo on Ubuntu using the installer and using virtualenv. There is another way to run Odoo, using Docker. If you not installed docker yet, you can see this link.

Odoo Logo

You can see the official Odoo Docker image at the Docker hub. There are many versions of Odoo in the Docker hub. We will use odoo:13 for this tutorial. The default odoo:13 image use Debian Buster (ver. 10.x) and Wkhtmltopdf 0.12.5.x. See https://github.com/odoo/docker/blob/master/13.0/Dockerfile

Docker logo

Preparation

For development with custom addons or enterprise addons, we need to create Dockerfile, docker-compose.yml, and odoo.conf. You can follow this step:

  • Create a new directory for project root. You can give any name for the directory.
  • Create a new directory, ex: addons-extra. Then put all your custom addons in there.
  • If you use enterprise edition, create a new directory, ex: addons-enterprise. Then put all enterprise addons in there.
  • Create docker-compose.yml. Copy the code below:
version: '3.1'

services:
  db:
    image: postgres:14 # we will use postgres:14 image from docker hub for database
	environment:
      - POSTGRES_USER=odoo # Set value of postgres credential
      - POSTGRES_PASSWORD=odoo
      - POSTGRES_DB=postgres
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - odoo-db-data:/var/lib/postgresql/data/pgdata # set postgresql data persistence

  web:
    image: odoo:15.0
    volumes:
      - ./addons-enterprise:/mnt/enterprise-addons # Mount volume between host and container, host_dir:container_dir
      - ./addons-extra:/mnt/extra-addons
      - ./config:/etc/odoo
      - odoo-web-data:/var/lib/odoo
    ports:
      - "9069:8069" # this will create connection port between host and container, this means host_port:container_port
    depends_on:
      - db # set depends on postgresql db
	environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=odoo

volumes:
  odoo-web-data:
  odoo-db-data:
  • Create a new directory config/ and a new file odoo.conf inside the config directory. Copy the code below:
[options]
addons_path = /mnt/enterprise-addons,/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
  • Optional, we can create a .dockerignore file used for ignoring some files to processed with docker such as .git file. Copy the code below:
LICENSE
VERSION
README.md
Changelog.md
Makefile
docker-compose.yml
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git
.gitignore
.gitkeep
# IDE
.idea
.vscode
  • And this is the tree result of the project directory.

Odoo docker

Build and Run

After setup, we need to build an image and run the container.

  • Make sure that pointer in the project root directory.
  • Then docker-compose run --service-ports web to run Odoo web & DB container.
  • For shortcut commands we can use docker-compose up to build image & start the container.
  • Open your browser and type localhost:9069 in the address bar.
  • When we run the container, it will automatically create docker volume odoo-db-data and odoo-web-data directory. All odoo data like attachment will be placed in odoo-web-data and all Postgres data will be placed in odoo-db-data.

That’s it. Thanks for reading.

Comments