In the dynamic world of Odoo development, establishing an efficient, isolated, and reproducible environment is paramount. Gone are the days of wrestling with local system dependencies and version conflicts. Today, we’re going to revolutionize your workflow by setting up a professional Odoo 19 Docker Devcontainer. This powerful combination offers an unparalleled development experience, ensuring consistency across teams and protecting your local machine from dependency clutter.
This comprehensive guide will walk you through every step, transforming your Visual Studio Code into a lean, mean Odoo development machine powered by Docker. Prepare to elevate your productivity and embrace a truly professional development setup.
Why Odoo 19 Docker Devcontainer? The Ultimate Development Edge
Before diving into the technicalities, let’s understand why an Odoo 19 Docker Devcontainer is the gold standard for modern Odoo development:
- Isolation: Your development environment is completely separate from your local operating system. No more “it works on my machine” issues, as all dependencies are encapsulated within the Docker container.
- Reproducibility: Everyone on your team can spin up an identical development environment with ease, guaranteeing consistent behavior and simplifying onboarding for new developers.
- Portability: Take your Odoo development environment with you. It runs seamlessly on any system with Docker Desktop and Visual Studio Code, be it Windows, macOS, or Linux.
- Version Control for Environment: Your entire development environment configuration (Dockerfile, docker-compose.yml, devcontainer.json) can be version-controlled, just like your code.
- Enhanced VS Code Integration: Devcontainers allow VS Code to run directly inside the Docker container, providing an integrated experience with all your favorite extensions and settings pre-configured for your Odoo project.
This tutorial is your definitive path to achieving this robust setup.
Prerequisites: Gearing Up for Your Odoo 19 Docker Devcontainer
To embark on this journey, ensure you have the following essential tools installed on your local machine:
- Docker Desktop: This application provides the Docker engine, Kubernetes, and an easy-to-use interface. Download and install it from the official Docker Desktop website. Ensure it’s running.
- Visual Studio Code (VS Code): Microsoft’s lightweight yet powerful code editor is central to our Devcontainer setup. Download it from the VS Code official website.
- VS Code Extensions: Once VS Code is installed, you’ll need a few extensions for seamless Odoo 19 Docker Devcontainer integration:
- Dev Containers: (formerly Remote – Containers) This crucial extension by Microsoft allows you to open any folder or repository inside a container.
- Docker: Also by Microsoft, this extension makes it easy to build, manage, and debug containerized applications.
- Python: The official Python extension for VS Code by Microsoft.
- Odoo File: An extension that helps with Odoo file and project structure creation.
- Odoo IDE: Provides intelligent code completion and other Odoo-specific IDE features.
- Pylance: (Usually included with Python extension) Provides advanced language features for Python.
- ESLint and Prettier: (Optional but highly recommended) For code linting and formatting, ensuring consistent code style.
With these prerequisites in place, let’s begin building your ultimate Odoo 19 Docker Devcontainer.
Step-by-Step Guide: Building Your Odoo 19 Docker Devcontainer
1. Project Initialization: The Foundation of Your Workspace
First, create a dedicated space for your Odoo 19 project. This will serve as the root of your repository.
* Create an empty folder on your local machine. For example, my_odoo19_project
.
* Inside this new folder, create a subfolder named .devcontainer
. **The leading dot is crucial!** This folder tells VS Code where to find the Devcontainer configurations.
* Within the .devcontainer
folder, create four essential files:
* devcontainer.json
: Configures how VS Code interacts with your container.
* docker-compose.yml
: Defines the services (Odoo, PostgreSQL, PGAdmin) that will run in your environment.
* Dockerfile
: Builds the custom Odoo image, installing all necessary system and Python dependencies.
* .env
: Stores environment variables, particularly for sensitive information or local path configurations.
2. Crafting the Dockerfile
: The Heart of Your Odoo 19 Devcontainer Image
The Dockerfile
is where we define the exact environment for your Odoo instance. It uses a multi-stage build, which is a best practice for creating lean, efficient Docker images.
Understanding the Multi-Stage Build:
- Stage 1 (
FROM python:3.12-slim-debian12 as base
): We start with a slim Debian-based Python 3.12 image. This stage focuses on installing all system-level dependencies required by Odoo.apt-get update
andapt-get install -y --no-install-recommends
: Installs fundamental tools likecurl
,git
,zip
,unzip
,build-essential
(for compiling C extensions),libpq-dev
(PostgreSQL development libraries), andzsh
(an optional but recommended shell).curl -sL ... | bash -
andapt-get install -y nodejs
: Installs Node.js andnpm
(Node Package Manager), essential for Odoo’s frontend assets like Less and Sass.npm install -g sass less
: Installs the Sass and Less pre-processors globally.WKHTMLTOPDF_VERSION
andcurl -sSL ... wkhtmltox.deb
: Installswkhtmltopdf
, a critical tool for generating PDF reports in Odoo. The script automatically detects your system architecture.apt-get install -y postgresql-client
: Installs the PostgreSQL client, allowing the Odoo container to connect to the PostgreSQL database container.apt-get clean
: Cleans up temporary files to reduce image size.
- Stage 2 (
FROM base
): This stage builds upon thebase
image from Stage 1, adding Odoo-specific configurations and user setup.pip install uv
: Installsuv
, a next-generation Python package installer that is significantly faster thanpip
and ideal for development. Check out uv’s GitHub page for more details.groupadd
anduseradd
: Creates a dedicatedodoo
user and group with specific IDs. Running Odoo as a non-root user is a security best practice.mkdir -p $ODOO_FILES_PATH && chown -R odoo:odoo $ODOO_FILES_PATH
: Creates the/var/lib/odoo
directory, which will serve as Odoo’s filestore (where attachments and other binary data are stored), and sets appropriate ownership.VOLUME $ODOO_FILES_PATH
: Declares this directory as a Docker volume, ensuring that Odoo’s data persists even if the container is removed.shopt -s histappend
,shopt -s histverify
: Configures Zsh to persist command history, a useful feature for developers.sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
: Installs Oh My Zsh, a popular framework for Zsh, enhancing terminal usability.git clone ... zsh-autosuggestions
,git clone ... zsh-completions
,git clone ... zsh-syntax-highlighting
: Installs highly recommended Zsh plugins for auto-completion, suggestions, and syntax highlighting, dramatically improving your command-line experience. You can find these on GitHub.USER odoo
andWORKDIR /home/odoo
: Switches to theodoo
user and sets the working directory, reinforcing the non-root user practice.
FROM python:3.12-slim-debian12 as base
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
zip \
unzip \
build-essential \
libpq-dev \
zsh \
&& rm -rf /var/lib/apt/lists/*
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get update && apt-get install -y nodejs
RUN npm install -g sass less
ARG WKHTMLTOPDF_VERSION=0.12.6
ARG WKHTMLTOIMAGE_VERSION=0.12.6
RUN ARCH=$(dpkg --print-architecture) \
&& if [ "$ARCH" = "amd64" ]; then ARCH="x86_64"; fi \
&& curl -sSL "https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.6/wkhtmltox_0.12.6-1.debian.11_${ARCH}.deb" -o wkhtmltox.deb \
&& apt-get install -y ./wkhtmltox.deb \
&& rm wkhtmltox.deb
RUN apt-get update && apt-get install -y postgresql-client
RUN apt-get clean
FROM base
RUN pip install uv
ARG UV_VENV=/opt/odoo-venv
ARG UV_NAME=odoo-venv
RUN groupadd -g 1000 odoo && \
useradd -u 1000 -g odoo -m odoo
ARG ODOO_FILES_PATH=/var/lib/odoo
RUN mkdir -p $ODOO_FILES_PATH && chown -R odoo:odoo $ODOO_FILES_PATH
VOLUME $ODOO_FILES_PATH
RUN echo 'shopt -s histappend' >> /home/odoo/.zshrc \
&& echo 'shopt -s histverify' >> /home/odoo/.zshrc
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
RUN git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
USER odoo
WORKDIR /home/odoo
3. Orchestrating Services with docker-compose.yml
This file defines the multi-container environment for your **Odoo 19 Docker Devcontainer** setup, including Odoo itself, its PostgreSQL database, and PGAdmin for database management.
odoo19_demo
service: This is your Odoo application container.build: context: . dockerfile: Dockerfile
: Instructs Docker Compose to build the Odoo image from theDockerfile
in the current directory.environment
: Defines internal container environment variables.ODOO_SERVER
andODOO_ENTERPRISE
will point to the mounted Odoo source code.volumes
: This is crucial for development..:/workspace
: Mounts your local project root (.
) into the container’s/workspace
directory. This means any code changes you make locally are instantly available inside the container.odoo_data:/var/lib/odoo
: Mounts the named Docker volumeodoo_data
to/var/lib/odoo
in the container, ensuring Odoo’s filestore data persists.
ports
: Maps container ports to your local machine ports.8069:8069
: For accessing the Odoo web interface.8071:8071
,8072:8072
: Typically used for debugging and other Odoo services.
depends_on: - db
: Ensures thedb
service (PostgreSQL) starts before Odoo.networks: - odoo_network
: Connects Odoo to our custom network.
db
service: This is your PostgreSQL database container.image: postgres:17.0-alpine
: Uses the official, lightweight PostgreSQL 17.0 Alpine image from Docker Hub.restart: always
: Automatically restarts the container if it stops.volumes: - db_data:/var/lib/postgresql/data
: Mounts a named volume for persistent database files.environment: - POSTGRES_PASSWORD=admin
: Sets the password for the default PostgreSQL user (postgres
).networks: - odoo_network
: Connects PostgreSQL to the shared network.
pgadmin
service: This provides a web-based interface for managing your PostgreSQL database.image: dpage/pgadmin4
: Uses the official PGAdmin 4 image from Docker Hub.ports: - "8085:80"
: Maps PGAdmin’s internal port 80 to your local machine’s port 8085.volumes: - pgadmin_data:/var/lib/pgadmin
: Mounts a named volume for persistent PGAdmin configuration and data.environment
: Sets the default email and password for PGAdmin login.depends_on: - db
: Ensures PostgreSQL is running before PGAdmin starts.networks: - odoo_network
: Connects PGAdmin to the shared network.
volumes
section: Defines the named Docker volumes forodoo_data
,db_data
, andpgadmin_data
to ensure data persistence across container restarts or removals.networks
section: Defines a custom bridge network namedodoo_network
. This allows the containers to communicate with each other using their service names (e.g.,odoo19_demo
can reach the database atdb
).
version: "3.9"
services:
odoo19_demo:
build:
context: .
dockerfile: Dockerfile
environment:
- ODOO_SERVER=/workspace/odoo
- ODOO_ENTERPRISE=/workspace/enterprise
volumes:
- .:/workspace
- odoo_data:/var/lib/odoo
ports:
- "8069:8069"
- "8071:8071"
- "8072:8072"
depends_on:
- db
networks:
- odoo_network
db:
image: postgres:17.0-alpine
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=admin
networks:
- odoo_network
pgadmin:
image: dpage/pgadmin4
restart: always
ports:
- "8085:80"
volumes:
- pgadmin_data:/var/lib/pgadmin
environment:
- PGADMIN_DEFAULT_EMAIL=admin@example.com
- PGADMIN_DEFAULT_PASSWORD=admin
networks:
- odoo_network
depends_on:
- db
volumes:
odoo_data:
db_data:
pgadmin_data:
networks:
odoo_network:
4. Configuring Environment Variables with .env
The .env
file holds sensitive or system-specific environment variables that shouldn’t be hardcoded into your docker-compose.yml
or version control.
ODOO_SERVER
: This must be the absolute path on your local machine to your Odoo 19 server source code.ODOO_ENTERPRISE
: Similarly, this must be the absolute path on your local machine to your Odoo 19 Enterprise modules source code (if applicable).
Example:
ODOO_SERVER=/Users/youruser/Documents/odoo/odoo19
ODOO_ENTERPRISE=/Users/youruser/Documents/odoo/enterprise19
Important Note: The transcript mentions mounting these folders in read-only mode (:ro
) in the docker-compose.yml
. This is a fantastic practice for stability, preventing accidental modifications to the core Odoo or Enterprise code. If you intend to modify these core modules, remove the :ro
flag. However, for standard module development, keeping them read-only is highly recommended.
5. Customizing Your VS Code Experience with devcontainer.json
This file tells VS Code how to connect to and configure your **Odoo 19 Docker Devcontainer**.
name
: A friendly name for your Devcontainer, displayed in VS Code.dockerComposeFile
: Points to yourdocker-compose.yml
file.service
: Specifies which service fromdocker-compose.yml
VS Code should connect to (ourodoo19_demo
service).workspaceFolder
: The path inside the container that VS Code will open. This matches the.:/workspace
volume mount in yourdocker-compose.yml
.customizations.vscode.extensions
: A list of VS Code extension IDs to automatically install within the Devcontainer. This ensures everyone on the team has the same tools. This includes the Python extensions, Odoo-specific extensions, and others like ESLint and Prettier for code quality.customizations.vscode.settings
: Specific VS Code settings that apply only when you are inside this Devcontainer.python.analysis.disabled
: Disables certain Pylance warnings that might be noisy in Odoo projects.python.defaultInterpreterPath
: Sets the default Python interpreter to ouruv
virtual environment inside the container.terminal.integrated.profiles.linux
andterminal.integrated.defaultProfile.linux
: Configures VS Code to usezsh
as the default terminal shell inside the container, leveraging our Oh My Zsh setup.
mounts
: Defines additional local host directories to mount into the container.source=${localEnv:HOME}/.zsh_history,target=/home/odoo/.zsh_history,type=bind,consistency=cached
: This mounts your local Zsh history file into the container, ensuring your command history persists across Devcontainer sessions.source=${localEnv:HOME}/.ssh,target=/home/odoo/.ssh,type=bind,consistency=cached
: This mounts your local SSH keys into the container. This is essential if your Odoo or custom module repositories are hosted on platforms like GitHub or GitLab and require SSH authentication. This way, you don’t need to reconfigure SSH inside the container.
remoteUser
: Specifies the user within the container that VS Code will operate as (ourodoo
user).
{
"name": "Odoo 19",
"dockerComposeFile": [
"docker-compose.yml"
],
"service": "odoo19_demo",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.debug-adapter-protocol",
"chelsea-innovations.odoo-file",
"odoodev.odoo-ide",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"settings": {
"python.analysis.disabled": [
"unresolved-import",
"reportMissingTypeStubs"
],
"python.defaultInterpreterPath": "/opt/odoo-venv/bin/python",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh",
"args": [
"-l"
]
}
},
"terminal.integrated.defaultProfile.linux": "zsh"
}
}
},
"mounts": [
"source=${localEnv:HOME}/.zsh_history,target=/home/odoo/.zsh_history,type=bind,consistency=cached",
"source=${localEnv:HOME}/.ssh,target=/home/odoo/.ssh,type=bind,consistency=cached"
],
"remoteUser": "odoo"
}
6. Establishing the Docker Network
Before VS Code can build your Devcontainer, you need to create the shared Docker network that your services will use.
- Open your local terminal (not inside VS Code yet).
- Run the following command:
docker network create odoo_network
This command creates a custom bridge network, allowing the Odoo, PostgreSQL, and PGAdmin containers to communicate seamlessly using their service names.
7. Launching Your Odoo 19 Docker Devcontainer
Now, it’s time to bring your **Odoo 19 Docker Devcontainer** to life!
- Open Visual Studio Code.
- Go to
File > Open Folder...
and select themy_odoo19_project
folder you created in Step 1. - VS Code will detect the
.devcontainer
folder and prompt you to “Reopen in Container”. Click this button. - If you don’t see the prompt, open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
) and type “Dev Containers: Reopen in Container”. - VS Code will now build the Docker image (this will take some time the first time, as it downloads base images and installs all dependencies defined in your
Dockerfile
) and then attach to the running Odoo container. - You’ll notice your VS Code window now shows
Dev Container: Odoo 19
in the bottom-left corner, indicating you are working directly inside the container! Your integrated terminal will also be running Zsh as theodoo
user.
8. Installing Odoo Dependencies within the Devcontainer
Once inside the Devcontainer, you need to install Odoo’s Python dependencies into the virtual environment created by uv
.
- Open a new terminal within VS Code (it will automatically be inside the Devcontainer).
- Initialize a Python project with
uv
(this will create theodoo-venv
directory as specified in the Dockerfile):
uv venv
- Now, install Odoo’s Python requirements. Replace
/workspace/odoo/requirements.txt
with the actual path to Odoo’srequirements.txt
file within your mounted Odoo server directory.
uv pip install -r /workspace/odoo/requirements.txt
The use of uv
here makes this process incredibly fast, allowing you to synchronize Odoo’s complex dependency tree in record time.
9. Setting Up PostgreSQL and the Odoo Database User
With your containers running, let’s configure the database.
- Open your web browser and navigate to
http://localhost:8085
. This will take you to the PGAdmin login page. Log in using the credentials you defined in your
docker-compose.yml
:- Email:
admin@example.com
- Password:
admin
- Email:
Once logged in, you need to add a new server connection for your PostgreSQL database:
- Right-click on “Servers” in the left sidebar and select “Register > Server…”.
- In the “General” tab, give it a meaningful name (e.g.,
Odoo 19 DB
). In the “Connection” tab:
- Host name/address:
db
(This is the service name of your PostgreSQL container indocker-compose.yml
, accessible directly within the Docker network). - Port:
5432
(the default PostgreSQL port). - Maintenance database:
postgres
- Username:
postgres
(the default user for the PostgreSQL image). - Password:
admin
(as defined indocker-compose.yml
).
- Host name/address:
- Click “Save”.
Now, create a dedicated Odoo user (role) for your database:
- Expand your new server connection, then “Login/Group Roles”.
- Right-click on “Login/Group Roles” and select “Create > Login/Group Role…”.
- In the “General” tab, set the Name to
odoo
. - In the “Definition” tab, set the Password to
odoo
. - In the “Privileges” tab, toggle “Can login?” to
Yes
, “Create database?” toYes
, and “Can create roles?” toYes
(or grant all relevant privileges for Odoo). - Click “Save”.
This odoo
user will be used by your Odoo application to connect to the database.
10. Configuring Odoo’s Server Settings
Next, we’ll create the Odoo configuration file (odoo.conf
). The Odoo Shortcut
VS Code extension (which you installed in your Devcontainer) simplifies this.
- In your VS Code terminal (inside the Devcontainer), ensure your virtual environment is active (it should automatically be if you restart the terminal, thanks to
devcontainer.json
settings). Use the Odoo Shortcut:
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
). - Type “Odoo: Create an Odoo config file”.
Follow the prompts:
- Config file path:
/workspace/odoo.conf
(or your preferred location within/workspace
). - Master password:
admin
(or choose your own, for database operations like creating new databases). - Database user:
odoo
(the user we just created in PGAdmin). - Database password:
odoo
(the password for theodoo
DB user). - Include Enterprise addons (if applicable).
- Include Odoo addons.
- Config file path:
- An
odoo.conf
file will be created in your/workspace
directory.
- Open the Command Palette (
Modify
odoo.conf
: Open the newly createdodoo.conf
file. Find thedb_host
line and change it todb
to ensure Odoo connects to the PostgreSQL service by its name within the Docker network:
[options]
...
db_host = db
db_port = 5432
db_user = odoo
db_password = odoo
...
(You might already have db_port
, db_user
, db_password
if you used the Odoo Shortcut to generate it.)
11. Running Your Odoo 19 Server
You’re almost there! Now, let’s start the Odoo server.
- In your VS Code terminal (inside the Devcontainer), activate the Python virtual environment if it’s not already:
source /opt/odoo-venv/bin/activate
- Run the Odoo server using your new configuration file:
/opt/odoo-venv/bin/odoo -c /workspace/odoo.conf
You will see Odoo logging messages indicating that it’s starting up.
12. Accessing Your Odoo 19 Instance
Finally, open your Odoo 19 development instance!
- Open your web browser and go to
http://localhost:8069
. - You should now see the Odoo database creation screen.
Fill in the details:
- Master Password:
admin
(or whatever you set inodoo.conf
). - Database Name:
odoo_19_dev
(or any name you prefer). - Email:
admin@example.com
- Password:
admin
(for the new Odoo admin user). - Language: Choose your preferred language.
- Country: Select your country.
- Load demo data: Tick this box if you want a pre-filled database for testing.
- Master Password:
- Click “Create database”. Odoo will then create the database, install basic modules, and redirect you to the Odoo dashboard.
Congratulations! You now have a fully operational and isolated **Odoo 19 Docker Devcontainer** development environment.
Unleashing Odoo 19’s New Power: In-App Documentation
As a testament to Odoo’s continuous innovation, Odoo 19 introduces a truly fantastic feature for developers: **in-app documentation**. This is a game-changer for understanding Odoo’s internal structure without constantly switching contexts.
To explore this, once your Odoo 19 instance is running and you’re logged into the database:
- Navigate to any module (e.g., Sales, Invoicing).
- In the URL, after the
web?#
part, simply adddoc=1
(or click on the “Doc” button if available in the top right corner). - For example, if your URL is
http://localhost:8069/web?#view_type=kanban&model=sale.order&action=118&menu_id=...
, change it tohttp://localhost:8069/web?doc=1#view_type=kanban&model=sale.order&action=118&menu_id=...
- You’ll be presented with an integrated documentation panel, showing model fields, methods, and other technical details directly within the Odoo interface. This allows you to quickly inspect object definitions, understand inheritance, and discover available methods – a massive boost for developer productivity!
Final Thoughts: Elevate Your Odoo Development
Setting up an **Odoo 19 Docker Devcontainer** is not just a technical exercise; it’s an investment in a more efficient, collaborative, and professional development future. By leveraging Docker’s isolation and VS Code’s deep integration, you eliminate common development headaches and create a robust, portable, and easily reproducible environment.
Embrace this powerful workflow, and experience the unparalleled benefits of a truly modern Odoo development setup. Happy coding!
URL: yourwebsite.com/odoo-19-docker-devcontainer-setup
Discover more from teguhteja.id
Subscribe to get the latest posts sent to your email.