- tested for Odoo v18, Postgres 17
Here is a simple and effective Docker setup for Odoo development. It features Docker compose “watch” capability for real-time code changes, which is ideal for custom module development.
**Core Components and Configuration:**The setup is orchestrated through a few key files, each serving a specific technical function:
compose.yml: This YAML file defines the multi-container application. It specifies two services: odoo and postgres. It maps host directories to container volumes for persistent data (odoo-data, pg-data) and local addon modules (./addons). It also handles port mapping and environment variable substitution from the .env file.
.env: A plaintext file used for defining environment variables, such as POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB, and the Odoo host port (ODEV_PORT). Using this file ensures that sensitive credentials are not hard-coded into the compose.yml or setup sh scripts.
setup sh: This Bash script is the primary execution tool. Its logic is designed to be idempotent, meaning it can be run multiple times without causing unintended side effects. The script automates a sequence of commands:
- Loads variables from .env.
- Executes docker compose down to clean up any previous services and volumes.
- Starts the postgres service and waits for its health check to pass.
- Runs a one-off Odoo container with the –init=base flag to initialize the database schema.
- Starts docker containers with WATCH mode
A critical feature for speeding up the development process is Docker’s Watch mode, configured within docker-compose. This feature automatically detects and syncs file changes from your local mounted volumes directly into the running container, eliminating the need to manually rebuild or restart the container after every code modification.
This method provides a clean separation of concerns, with the Dockerfile defining the environment, compose.yml orchestrating the services, and the setup script automating the workflow.