Skip to main content

Interacting with the Odoo Docker container

A practical guide to interacting with Odoo running in Docker containers, including shell access, database operations, and service management.

A quick run down on interacting with an Odoo Docker container, including command-line access, database operations, and service management.

Prerequisites

This article assumes you have:

Finding our container

Before we can directly interact with our container, we need to verify the name assigned to it:

shell > docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED       STATUS        PORTS                                                      NAMES
7882b85f9528   odoo:15.0     "/entrypoint.sh odoo"    23 hours ago  Up 12 hours   0.0.0.0:8069->8069/tcp, :::8069->8069/tcp, 8071-8072/tcp   odoo_web_1
02acb15639a3   postgres:15   "docker-entrypoint.s…"   23 hours ago  Up 12 hours   5432/tcp                                                   odoo_db_1

In this listing we can see that the Odoo container is called odoo_web_1 and the PostgreSQL container is odoo_db_1.

Running shell commands

With the name of our container in hand, we can issue various commands:

# run an interactive shell in the container
docker exec -ti odoo_web_1 bash

# list files in the entrypoint directory; colorise output
docker exec -ti odoo_web_1 ls -al --color=auto

# find out which user Odoo is running under
docker exec -ti odoo_web_1 id
# outputs something like this:
# uid=101(odoo) gid=101(odoo) groups=101(odoo)

Tip

You can run any Linux command available within the container using the `docker exec` command. This gives you full access to troubleshoot issues or modify configurations.

Python interactive shell

Odoo provides a helpful interactive shell for running Python code directly within the Odoo environment:

docker exec -it odoo_web_1 odoo shell --shell-interface=python

This gives you direct access to Odoo's API and data models for debugging or custom operations.

Note

Exit the Python shell by pressing `ctrl+d` or typing `exit()`.

Interacting with the Odoo database container

We can interact with the PostgreSQL database container to perform database operations directly.

Listing available databases

docker exec odoo_db_1 psql -U odoo -l

Output:

                                             List of databases
   Name    | Owner | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider | Access privileges
-----------+-------+----------+------------+------------+------------+-----------------+-------------------
 postgres  | odoo  | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 template0 | odoo  | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/odoo          +
           |       |          |            |            |            |                 | odoo=CTc/odoo
 template1 | odoo  | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/odoo          +
           |       |          |            |            |            |                 | odoo=CTc/odoo
 test01    | odoo  | UTF8     | C          | en_US.utf8 |            | libc            |
(4 rows)

Interactive database shell

Get an interactive PostgreSQL shell:

docker exec -ti odoo_db_1 psql -d postgres -U odoo

Once connected, you can run various psql commands:

postgres-# \conninfo
You are connected to database "postgres" as user "odoo" via socket in "/var/run/postgresql" at port "5432".

Connect to a specific database:

postgres-# \c test01
You are now connected to database "test01" as user "odoo".

List all tables in the database:

test01-# \dt
                                    List of relations
 Schema |                              Name                              | Type  | Owner
--------+----------------------------------------------------------------+-------+-------
 public | account_account                                                | table | odoo
 public | account_account_account_balance_report_rel                     | table | odoo
 public | account_account_account_common_account_report_rel              | table | odoo
 ...
(430 rows)

Exit the psql shell by pressing ctrl+d.

Creating a new database

We can create and initialise a new database directly from the command line:

docker exec -ti odoo_web_1 odoo -d test02

Caution

Creating a new database typically requires administrative access in production environments. Use appropriate credentials and follow security best practices.

Connecting through local PostgreSQL client

If PostgreSQL is installed on your host system, you can connect directly:

# login as user docker on localhost on port 5432
psql postgres://docker:password@localhost:5432/test01

This can be useful for database backups or using GUI tools like pgAdmin.

Managing the Odoo service

Investigating the Odoo service

Connect to the container and check running services:

docker exec -ti odoo_web_1 bash
shell > service --status-all
 [ ? ]  hwclock.sh
 [ + ]  odoo
 [ - ]  x11-common

Check the Odoo service status:

shell > service odoo status
Status of odoo: stopped

Find the Odoo binary location:

shell > which odoo
/usr/bin/odoo

Stopping and starting Odoo

You can stop the Odoo server from within the container:

odoo --stop

To start it again, you can use the service command or run the Odoo binary directly.

Managing volumes

Docker volumes store persistent data for Odoo. Understanding how to manage them is essential for maintenance.

Removing volumes

Warning

Removing volumes permanently deletes data. Always back up important data before removing volumes.
docker volume rm odoo_odoo-web-data

After removing a volume, you might encounter issues with missing files and unstyled interfaces. This happens because the filestore containing web assets was removed.

For fixing missing assets, you can regenerate assets files using command-line operations.

Fixing PDF printing errors

If you encounter errors like:

Odoo is unable to merge the PDFs attached to the following records:
INV/2022/00013

You can fix this by:

  1. Enable Developer Mode
  2. Click on the bug icon in Odoo's navbar
  3. Select Manage Attachements and delete any attached PDFs

Odoo command reference

To see all available Odoo command-line options:

docker exec -ti odoo_web_1 odoo --help

This provides a comprehensive list of all commands and options for managing Odoo through the command line.

Common operations summary

Operation Command
Access shell docker exec -ti odoo_web_1 bash
Python shell docker exec -it odoo_web_1 odoo shell --shell-interface=python
List databases docker exec odoo_db_1 psql -U odoo -l
Create database docker exec -ti odoo_web_1 odoo -d new_db_name
Access logs docker logs odoo_web_1
Restart container docker restart odoo_web_1

Resources