Launching Odoo for Local Development Using Docker Compose


Odoo is a powerful open-source ERP and CRM system that provides a comprehensive suite of business applications. Whether you’re a developer looking to customize Odoo modules or a business owner wanting to test out Odoo’s features before deploying it in production, setting up Odoo for local development using Docker Compose is a convenient and efficient way to get started. This article will guide you through the process of launching Odoo locally using Docker Compose.

Why Use Docker Compose for Odoo?

Docker Compose simplifies the process of managing multi-container Docker applications by allowing you to define and orchestrate all the necessary services in a single YAML file. For Odoo, this typically includes the Odoo application itself and a PostgreSQL database. Using Docker Compose for Odoo development offers several benefits:

  1. Consistency: Docker ensures that your Odoo environment is consistent across different machines, avoiding the “works on my machine” problem.
  2. Isolation: Each component runs in its own container, isolating dependencies and avoiding conflicts with other projects.
  3. Portability: You can easily share your development setup with other team members by distributing the Docker Compose file.
  4. Ease of Setup: Docker Compose automates the setup process, reducing the time needed to configure and launch Odoo.

Prerequisites

Before you begin, make sure you have the following installed on your machine:

  • Docker: The containerization platform that allows you to run Odoo and PostgreSQL in isolated environments.
  • Docker Compose: A tool for defining and running multi-container Docker applications.

Step-by-Step Guide to Launching Odoo with Docker Compose

Step 1: Create a Project Directory

First, create a directory for your Odoo project. This directory will contain the Docker Compose file and any other files related to your Odoo setup.

mkdir odoo-docker
cd odoo-docker

Step 2: Write the Docker Compose File

Create a docker-compose.yml file in your project directory. This file will define the Odoo and PostgreSQL services.

services:
  web:
    image: odoo:16.0
    depends_on:
      - db
    ports:
      - "8069:8069"
    environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=odoo
    volumes:
      - odoo-web-data:/var/lib/odoo
      - ./addons:/mnt/extra-addons
      - ./config:/etc/odoo
    networks:
      - odoo-network

  db:
    image: postgres:13
    environment:
      POSTGRES_DB: odoo
      POSTGRES_USER: odoo
      POSTGRES_PASSWORD: odoo
    volumes:
      - odoo-db-data:/var/lib/postgresql/data
    networks:
      - odoo-network

volumes:
  odoo-web-data:
  odoo-db-data:

networks:
  odoo-network:
Explanation:
  • Odoo Service (web):
  • Image: We use the official Odoo Docker image, specifying the version (16.0).
  • Depends On: The web service depends on the db service, ensuring that PostgreSQL starts before Odoo.
  • Ports: The Odoo service is mapped to port 8069 on your localhost.
  • Environment Variables: Defines database connection details (HOST, USER, PASSWORD).
  • Volumes: Mounts local directories for persistent storage and for custom addons or configuration files.
  • Networks: Both services are placed on a custom Docker network (odoo-network) to facilitate communication.
  • PostgreSQL Service (db):
  • Image: We use the official PostgreSQL Docker image (13).
  • Environment Variables: Sets up the database with a name (POSTGRES_DB), user (POSTGRES_USER), and password (POSTGRES_PASSWORD).
  • Volumes: Mounts a local volume to persist database data.
  • Networks: The PostgreSQL service also connects to the odoo-network.

Step 3: Customize Your Setup

You may want to customize your setup based on your development needs:

  • Addons Directory: Place your custom Odoo modules in the addons directory.
  • Configuration Files: Place any custom configuration files in the config directory.
  • Database Management: You can customize the PostgreSQL service by adjusting the environment variables for different database names, users, or passwords.

Step 4: Launch Odoo

With your docker-compose.yml file ready, you can now launch Odoo with the following command:

docker-compose up -d

This command will download the necessary Docker images (if not already available), create containers for Odoo and PostgreSQL, and start the services in detached mode.

Step 5: Access Odoo

Once the services are up and running, you can access the Odoo web interface by navigating to http://localhost:8069 in your web browser.

  • Initial Setup: When you first access Odoo, you’ll be prompted to set up a new database. Use the credentials you specified in the docker-compose.yml file (odoo as the username and password).

Step 6: Managing Your Containers

Here are a few useful Docker Compose commands for managing your Odoo setup:

  • View Logs: Check the logs for both Odoo and PostgreSQL:
  docker-compose logs -f
  • Stop the Services: Stop all running containers:
  docker-compose down
  • Rebuild Containers: Rebuild the containers if you make changes to the Dockerfile or docker-compose.yml:
  docker-compose up -d --build

Conclusion

Setting up Odoo for local development using Docker Compose is a straightforward process that leverages the power of containerization to create a consistent and portable development environment. By following the steps outlined in this guide, you can have a fully functional Odoo instance up and running in just a few minutes, ready for customization, testing, and development. Whether you’re new to Odoo or a seasoned developer, Docker Compose provides a robust platform for developing and experimenting with Odoo modules and configurations.

,