Dockerizing an Odoo custom module makes it easier to deploy, manage, and scale Odoo instances while ensuring consistency across different environments. In this guide, we will walk through creating a Dockerfile, building a Docker image, running a container, and pushing the image to Docker Hub.
Before starting, ensure you have the following:
* Docker Installed: Download and install Docker from the official website.
* Docker Hub Account: Required for storing and sharing your Docker images.
* Odoo Custom Module: A custom Odoo module ready for deployment.
Create a Project Directory
Create a dedicated directory for your Odoo module and Docker files:
mkdir odoo_custom && cd odoo_custom
Next, create a folder for your custom module:
mkdir module
cp -r /path/to/your/module module/
Ensure your module has essential files like __init__.py, __manifest__.py, and other necessary components.
Create a Dockerfile
A Dockerfile defines how to build your Docker image. Create a Dockerfile inside odoo_custom and add the following:
# syntax=docker/dockerfile:1
# Use the base image odoo:latest
FROM odoo:latest
# Install Python dependencies
RUN pip3 install --no-cache-dir --break-system-packages requests beautifulsoup4 lxml flake8
# Copy custom addons from your host to the container
COPY ./custom_addon /mnt/extra-addons
# Set appropriate permissions
RUN chown -R odoo:odoo /mnt/extra-addons
# Expose necessary ports
EXPOSE 8069
# Run Odoo
CMD ["odoo"]
* FROM odoo:latest: Uses the latest official Odoo image.
* RUN pip3 install ... : Installs external Python dependencies (requests, beautifulsoup4, lxml, flake8).
* COPY ./custom_addon /mnt/extra-addons: Copies your module to the container.
* RUN chown -R odoo:odoo /mnt/extra-addons: Ensures correct permissions.
* EXPOSE 8069: Opens Odoo’s default port.
* CMD ["odoo"]: Starts Odoo when the container runs.
Build the Docker Image
Run the following command to build the Docker image:
docker build -t your-dockerhub-username/odoo-custom.
This creates a Docker image named odoo-custom.
To test your Odoo module, run the container:
docker run -p 8069:8069 your-dockerhub-username/odoo-custom
Verifying the Module:
Open a browser and go to http://localhost:8069.
Log in to Odoo, navigate to the Apps menu.
Search for your module to check if it is installed correctly.
Push the Image to Docker Hub
To share your image with others, push it to Docker Hub.
Log in to Docker Hub:
docker login
Enter your Docker Hub credentials when prompted.
Tag Your Image:
docker tag your-dockerhub-username/odoo-custom your-dockerhub-username/odoo-custom:latest
Push the Image:
docker push your-dockerhub-username/odoo-custom:latest
Your image is now stored on Docker Hub and can be used anywhere.
Pull and Run the Image from Docker Hub
To pull the image:
docker pull your-dockerhub-username/odoo-custom:latest
To run a container using the image:
docker run -p 8069:8069 your-dockerhub-username/odoo-custom:latest
Using Docker Compose
For a more structured setup, use Docker Compose to manage Odoo and PostgreSQL. Create a docker-compose.yml file:
version: '3.1'
services:
db:
image: postgres:15
environment:
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
POSTGRES_DB: odoo
odoo:
image: your-dockerhub-username/odoo-custom:latest
ports:
- "8069:8069"
depends_on:
- db
Start the services:
docker-compose up -d
With your image now stored on Docker Hub, you can easily deploy and maintain Odoo instances anywhere, ensuring seamless consistency across different environments.
To read more about How to Convert a Container Into an Image & Push to Docker Hub, refer to our blog How to Convert a Container Into an Image & Push to Docker Hub.