Enable Dark Mode!
how-to-set-up-multiple-odoo-instances-in-a-single-docker-compose-yaml.jpg
By: Cybrosys Technologies

How to Set Up Multiple Odoo Instances in a Single Docker Compose YAML

Technical

Running multiple Odoo instances on a single system can be a challenge, but using Docker Compose makes the setup straightforward and manageable. In this guide, we will demonstrate how to configure and deploy two separate Odoo instances within a single Docker Compose YAML file, allowing you to manage your Odoo environments efficiently.

Why Use Docker Compose?

Docker Compose allows you to define and orchestrate multiple services within a single configuration file. For deploying two Odoo instances, Docker Compose provides an easy way to handle the different containers, ensuring that each instance operates in its own isolated environment. This method simplifies complex deployments, ensures easier management of resources, and minimizes configuration issues.

Advantages of Running Multiple Odoo Instances with Docker Compose:

1. Separation and Isolation: Each Odoo instance operates independently in its own container, preventing conflicts and ensuring secure isolation between them.

2. Convenient Management: A single docker-compose.yml file makes it easy to manage both instances, ensuring you can scale or adjust them as needed.

3. Consistency Across Environments: By using Docker’s official Odoo images, you can ensure that each instance is set up with the same configuration, avoiding discrepancies between environments.

To run Odoo 18 using Docker, two containers are necessary: one for Odoo and another for the PostgreSQL database. These containers can be set up using the official Odoo and PostgreSQL images available on Docker Hub.

Before installing Docker from scratch, it’s advisable to remove any existing conflicting packages to prevent installation issues.

sudo apt-get remove docker docker-engine docker.io docker-doc docker-compose podman-docker containerd runc
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

Additionally, images, containers, volumes, and custom configuration files are not deleted automatically. To remove them manually, follow these steps:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Installation

Refresh the package index to ensure you have the latest available versions:

sudo apt-get update

Before installing Docker Engine on a new system, you must configure the Docker APT repository. This setup allows you to install and update Docker directly from the repository.

Import Docker’s official GPG key:
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Add the Docker repository to APT sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Use the following command to install the latest Docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
To ensure the installation of Docker was successful, you can run the official Hello World image as a test.
sudo docker run hello-world
This command pulls a test image and launches it in a container. Once the container starts, it displays a confirmation message and then shuts down.

How to Set Up Odoo Using Docker

Setting up Odoo with Docker simplifies deployment and management. Follow these steps to get started.
Step 1: Create the Docker Compose File
Start by creating a directory by running the following command.
mkdir docker_setup
Create a new file named docker-compose.yml inside the directory.
cd docker_setup
touch docker-compose.yml
This file will be used to define and manage your Docker services.
Step 2: Define the PostgreSQL Service
Need to open the docker-compose.yml by running the command.
sudo nano docker-compose.yml
In your docker-compose.yml file, define the PostgreSQL service. This service will use the PostgreSQL image from Docker Hub.
services:
  db-main:  # Name of the PostgreSQL service
    image: postgres:15  # PostgreSQL image version 15
    container_name: db-main  # Name of the container
    environment:  # Environment variables for PostgreSQL
      - POSTGRES_USER=odoo_main
      - POSTGRES_PASSWORD=odoo_main
      - POSTGRES_DB=postgres
Step 3: Define the Odoo Service
Next, define the Odoo service. This service will use the Odoo image from Docker Hub and will depend on the PostgreSQL service.
odoo-main:  # Name of the Odoo service
    image: odoo:18.0  # Odoo image version 18.0
    container_name: odoo-main  # Name of the container
    depends_on:  # Ensure PostgreSQL starts before Odoo
      - db-main
    environment:  # Environment variables for Odoo
      - HOST=db-main
      - USER=odoo_main
      - PASSWORD=odoo_main
    ports:  # Port mapping
      - "8081:8069"  # Map port 8069 on your host to port 8081 on the container
Step 4: Combine All Services
Combine all the services into a single docker-compose.yml file.
services:
  db-main:  # PostgreSQL service for main environment
    image: postgres:15
    container_name: db-main
    environment:
      - POSTGRES_USER=odoo_main
      - POSTGRES_PASSWORD=odoo_main
      - POSTGRES_DB=postgres
  odoo-main:  # Odoo service for main environment
    image: odoo:18.0
    container_name: odoo-main
    depends_on:
      - db-main
    environment:
      - HOST=db-main
      - USER=odoo_main
      - PASSWORD=odoo_main
    ports:
      - "8081:8069"
  db-staging:  # PostgreSQL service for staging environment
    image: postgres:15
    container_name: db-staging
    environment:
      - POSTGRES_USER=odoo_staging
      - POSTGRES_PASSWORD=odoo_staging
      - POSTGRES_DB=postgres
  odoo-staging:  # Odoo service for staging environment
    image: odoo:18.0
    container_name: odoo-staging
    depends_on:
      - db-staging
    environment:
      - HOST=db-staging
      - USER=odoo_staging
      - PASSWORD=odoo_staging
    ports:
      - "8082:8069"
Step 5: Start the Services
Navigate to the directory containing your docker-compose.yml file and run the following command to start the services:
sudo docker compose up

Step 6:  Accessing Services

After the services are up and running, you can access each service using the custom port mappings defined in your docker-compose.yml file.

Use http://localhost:8081 for running odoo-main and http://localhost:8082 for running odoo-staging.

To read more about How to Install Odoo 16 in Docker?, refer to our blog How to Install Odoo 16 in Docker.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message