Skip to main content

A step-by-step guide to creating a development and debugging environment for Odoo using Docker and vscode

April 25, 2025

Setting Up Up Odoo with Docker and VSCode

This guide provides a step-by-step process to set up and debug Odoo using Docker and Visual Studio Code (VSCode).

1. Prerequisites

Install Required Tools

  • Docker: Install from the official Docker installation page.
  • Git: Install using the appropriate guide for your operating system.
  • Linux Users: Add your user to the Docker group to run commands without sudo:
    sudo usermod -a -G docker <your_username>

2. Create Directory Structure

Run the following command to create the required directory structure:

echo -e "\n=== Creating Directory Structure ==="
mkdir -p $HOME/odoo
mkdir -p $HOME/odoo/14.0/src
mkdir -p $HOME/odoo/14.0/src/odoo
mkdir -p $HOME/odoo/14.0/src/enterprise  # optional
mkdir -p $HOME/odoo/varlib
mkdir -p $HOME/odoo/shared_postgres_data

The structure includes:

  • Root Directory: $HOME/odoo
  • Version-Specific Directories (e.g., for Odoo 14.0): $HOME/odoo/14.0
  • Source Code Directories:
    • $HOME/odoo/14.0/src/odoo
    • $HOME/odoo/14.0/src/enterprise (optional)
  • Filestore Directory: $HOME/odoo/varlib
    Ensure the containerized Odoo has write access to this directory.
  • Postgres Data Directory: $HOME/odoo/shared_postgres_data
  • Tutorial Files: Clone the tutorial repository:
    cd $HOME/odoo && git clone https://github.com/Pro-Tech777/Docker-Odoo-Debug-Developer-Environment.git docker-odoo-debug

3. Set Up Database Server

Run a Postgres container for Odoo:

docker run -d \
   -e POSTGRES_USER=odoo \
   -e POSTGRES_PASSWORD=odoo \
   -e POSTGRES_DB=postgres \
   -e PGDATA=/var/lib/postgresql/data\
   --shm-size=1g \
   --restart always \
   -v $HOME/odoo/shared_postgres_data:/var/lib/postgresql/data\
   -p 5432:5432 \
   --name db-shared postgres:14

Alternatively, use Docker Compose for the database stack:

version: '3.8'
services:
  db-shared:
    image: postgres:14
    container_name: db-shared
    environment:
      POSTGRES_USER: odoo
      POSTGRES_PASSWORD: odoo
      POSTGRES_DB: postgres
      PGDATA: /var/lib/postgresql/data
    shm_size: '1g'
    restart: always
    volumes:
      - $HOME/odoo/shared_postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

Save the above as docker-compose.yml and run:

docker-compose up -d

4. Clone Odoo Source Code

  • Clone the Odoo source code (e.g., version 14.0):
    cd $HOME/odoo/14.0/src &&& git clone -b 14.0 --single-branch --depth=1 https://github.com/odoo/odoo.git
  • To update the source code later:
    cd $HOME/odoo/14.0/src/odoo && git pull

5. Configure VSCode

  • Install Extensions:
    • Python
    • Pylint
    • Docker
  • Copy Configuration Files:
    • Copy the vscode. directory from the docker-odoo-debug repository to your project root ($HOME/odoo).
    • If you have existing configuration files, merge the tutorial's vscode. settings into your own.
  • Update Configuration Files:
    • In vscode/settings.json, set the odooVersion variable to your Odoo version (e.g., 14.0).
    • In vscode/launch.json, configure launch settings as needed.
    • In vscode/tasks.json, verify that tasks are correctly configured.

6. Configure Odoo

Update the odoo.conf file:

  • Ensure paths for the filestore and source code are correct.
  • Add custom add-ons paths if needed.

7. Build Docker Image

  • Build a custom Docker image:
    docker build -t my-odoo:14.0 $HOME/odoo/docker-odoo-debug/14.0
  • Optimize by disabling the docker-build dependency in vscode/tasks.json:
    // Comment out or remove:
    "dependsOn": [ "build-image"]

8. Handle Permissions (If Needed)

If you encounter permission errors, run one of the following:

  • Inside the container:
    docker exec -u root <container_name_or_id> bash -c "mkdir -p /home/odoo/odoo/varlib && chown -R odoo:odoo /home/odoo/odoo/varlib && chmod -R 755 /home/odoo/odoo/varlib"
  • On the host:
    sudo chmod -R777 $HOME/odoo

9. Pre-Flight Checklist

Before starting, confirm the following:

  • Git is installed.
  • Docker is installed from the official Docker page.
  • Odoo source code is cloned from Git.
  • Odoo filestore directory is created and accessible.
  • VSCode extensions (Python, Pylint, Docker) are installed.
  • Postgres database server is running.
  • docker-odoo-debug repository is cloned.
  • Configuration files are copied to the project's vscode. directory.
  • odoo.conf paths for filestore and source code are correct.
  • Custom add-ons path is added to odoo.conf if required.
  • settings.json odooVersion is set to the project's Odoo version.
  • tasks.json paths are correctly set.
  • Docker image is built if reused across projects.
  • "dependsOn": ["build-image"] is disabled in tasks.json.

10. Start Debugging

With the setup completed, you can now debug Odoo using Docker and VSCode. Refer to the tutorial repository for additional debugging tips.