Hi Subin
Yeah, I’ve done this a few times — building a custom Docker image for Odoo from source is totally doable and actually gives you more control, especially if you’re integrating custom modules or want to avoid the limitations of the official image.
Here’s a breakdown of best practices from real-world use:
Base Image and Dockerfile Setup:
Start with a slim base (like python:3.10-slim) to keep the image clean and efficient. Clone directly from the Odoo GitHub repo:
FROM python:3.10-slim
ENV LANG C.UTF-8
# System deps
RUN apt-get update && apt-get install -y \
git build-essential libpq-dev libxml2-dev libxslt1-dev \
libldap2-dev libsasl2-dev libjpeg-dev zlib1g-dev \
libjpeg-dev libpng-dev liblcms2-dev libblas-dev libatlas-base-dev \
libffi-dev libssl-dev libevent-dev \
&& apt-get clean
# Create odoo user
RUN useradd -ms /bin/bash odoo
# Clone Odoo
RUN git clone --depth 1 --branch 18.0 https://github.com/odoo/odoo.git /opt/odoo
WORKDIR /opt/odoo
# Install Python dependencies
COPY requirements.txt /opt/odoo/
RUN pip install -r requirements.txt
# Set permissions
RUN chown -R odoo:odoo /opt/odoo
USER odoo
CMD ["python3", "odoo-bin", "-c", "/etc/odoo/odoo.conf"]
Handle Dependencies
-
Use requirements.txt from the Odoo repo or generate it from setup/.
-
Keep PostgreSQL outside the container — either use Docker Compose or an external DB server. Make sure it’s tuned for Odoo (see previous PostgreSQL answer).
-
For wkhtmltopdf, use the static build (especially in production). Install it manually into the image.
Custom Addons & Config
Best practice is to mount custom addons via a volume or include them in the build:
COPY ./custom-addons /mnt/custom-addons
And make sure addons_path in odoo.conf includes:
addons_path = /opt/odoo/addons,/mnt/custom-addons
You can also use ARGs or ENV vars to toggle between dev/prod config files.
Known Gotchas & Optimizations
-
Don’t install too much into your image. Use multistage builds if needed.
-
Always pin the Git branch/tag to avoid weird surprises after future pushes.
-
Use healthchecks in Docker Compose to restart on failures.
-
Consider using PIP caching or building wheels for faster builds in CI/CD.
-
For production, run behind a reverse proxy (like Nginx) and isolate PostgreSQL.
Great Repos to Explore
-
Doodba (by Tecnativa) – very advanced, for serious DevOps. Uses Docker + git submodules + Makefiles + pre-commit hooks.
-
Odoocker (by yelizariev) – simple and clean, especially good for learning the build process.
-
OCA’s docker-odoo-project – community-driven, focused on modular development.