This is a step-by-step guide on how to setup odoo from souce and using Docker to create a PostgreSQL database and build an Odoo server on Ubuntu.
Note: This guide demonstrates usage in the
/root
directory. You may use any user account of your choice.
Upload Project Files
Use a tool like MobaXterm to upload files to your server.
Download the free version here: MobaXterm
After downloading and installing, connect to your Ubuntu server and upload the zip file.
PostgreSQL Docker Compose Setup
- Upload the file
postgresql.zip
to the/root
folder. - Unzip it:
cd /root
unzip -o postgresql.zip
Expected output:
Archive: postgresql.zip
creating: postgresql/data/
inflating: postgresql/docker-compose.yml
Here is the docker-compose.yml
content:
services:
postgres_db:
image: postgres:16
container_name: postgres_db
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=your-password
ports:
- "5539:5432"
volumes:
- /root/postgresql/data:/var/lib/postgresql/data
restart: unless-stopped
networks:
- internal_shared_net
shm_size:'9g'
networks:
internal_shared_net:
external: true
Note: PostgreSQL data is stored in
/root/postgresql/data
, so it persists even if the container is removed.
When deploying multiple containers using Docker Compose, using a shared network allows containers to communicate internally using service names instead of fixed IP addresses.
The internal_shared_net
network allows other containers (like Odoo) to connect to PostgreSQL.
To create the external Docker network:
docker network create internal_shared_net
If you already have an existing external Docker network, update your network configuration in the docker-compose.yml file
You should also set the shm_size
parameter in the Docker Compose file to avoid a "disk full" error like shown in the screenshot. The shm_size should be greater than the value of shared_buffers in the postgresql.conf.
For example: shared_buffers = 8GB, shm_size = '9g'.
Navigate to the project folder and start the container:
cd /root/postgresql/
docker compose up -d
If You encounter error: postgres_db | initdb: error: directory "/var/lib/postgresql/data" exists but is not empty You need to delete the data folder, then create the folder again.
You should see logs similar to:
postgres_db | creating subdirectories ... ok
postgres_db | syncing data to disk ... ok
To enter the container and connect to PostgreSQL:
docker exec -it postgres_db /bin/bash
psql -h postgres_db -U odoo -d postgres
Setup Odoo 15
Next, upload odoo15_docker.zip
to /root
and unzip it:
cd /root
unzip odoo15_docker.zip
Odoo Docker Compose
services:
odoo_container:
container_name: odoo_15
build:
context: .
dockerfile: Dockerfile
ports:
- "8869:8069"
- "8872:8072"
volumes:
- ./custom-addons:/opt/odoo15/custom-addons/
- ./logs:/var/log/odoo/
- ./config/odoo15.conf:/etc/odoo15.conf
- ./odoo-data:/opt/odoo15/.local/share/Odoo/
- ./lib:/opt/odoo15/.local/lib # python lib
- ./bin:/opt/odoo15/.local/bin #python bin
restart: unless-stopped
networks:
- internal_shared_net
networks:
internal_shared_net:
external: true
The custom-addons folder is mounted into the container to store custom Odoo modules.
The logs folder is mounted to persist Odoo logs outside the container.
The configuration file odoo15.conf is also mounted from the host.
Set permission for folder logs
cd /root/odoo15_docker/
chmod -R 777 logs
chmod -R 777 odoo-data/
chmod -R 777 lib/
chmod -R 777 bin/
Odoo Configuration File: config/odoo15.conf
[options]
admin_passwd = your_password
logfile = /var/log/odoo/odoo.log
db_host = postgres_db
db_port = 5432
db_user = odoo
db_password = your_password_db
; Addons path
addons_path = /opt/odoo15/odoo/addons,/opt/odoo15/custom-addons
server_wide_modules = base,web
Note: if you set workers, you must enable proxy = True and using nginx as reverse proxy
workers = 4
max_cron_threads = 2
proxy = True
Odoo Dockerfile
FROM ubuntu:22.04
LABEL maintainer="MrHieu84-nnhieu.htb@gmail.com"
ENV LANG=C.UTF-8
# Set the timezone to Asia/Ho_Chi_Minh (Saigon, Vietnam)
ENV TZ=Asia/Ho_Chi_Minh
# Set timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
# Update the system and install necessary packages
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git \
wget \
unzip \
openssh-server \
python3-pip \
build-essential \
python3-dev \
python3-venv \
python3-wheel \
libfreetype6-dev \
libxml2-dev \
libzip-dev \
libldap2-dev \
libsasl2-dev \
python3-setuptools \
node-less \
libjpeg-dev \
zlib1g-dev \
libpq-dev \
libxslt1-dev \
libtiff5-dev \
libjpeg8-dev \
libopenjp2-7-dev \
liblcms2-dev \
libwebp-dev \
libharfbuzz-dev \
libfribidi-dev \
libxcb1-dev \
wkhtmltopdf \
&& rm -rf /var/lib/apt/lists/*
# Create user odoo15 with home directory and shell
RUN useradd -m -d /opt/odoo15 -U -r -s /bin/bash odoo15
USER odoo15
# Clone Odoo repository
RUN git clone https://www.github.com/odoo/odoo --depth 1 --branch 15.0 /opt/odoo15/odoo
# Make the requirements file readable by all users
RUN chmod a+r /opt/odoo15/odoo/requirements.txt
USER root
# Modify requirements.txt to change gevent version, fix when install on ubuntu version 24.2, on ubuntu 22.04 don't need
RUN sed -i 's/gevent==21.8.0/gevent==24.11.1/' /opt/odoo15/odoo/requirements.txt
RUN sed -i 's/greenlet==1.1.2/greenlet==3.1.1/' /opt/odoo15/odoo/requirements.txt
RUN pip3 install wheel
RUN pip3 install -r /opt/odoo15/odoo/requirements.txt
USER odoo15
CMD ["/opt/odoo15/odoo/odoo-bin", "-c", "/etc/odoo15.conf"]
Build Odoo Image and Start the Server
Change directory and start Odoo:
cd /root/odoo15_docker/
docker compose up -d
Output:
=> [odoo_container 11/11] RUN pip3 install -r /opt/odoo15/odoo/requirements.txt 451.2s
=> [odoo_container] exporting to image 62.7s
...
Once started, you will see logs like:
odoo_15 | INFO ? odoo.modules.loading: init db
odoo_15 | INFO mydb odoo.modules.loading: loading 1 modules...
odoo_15 | INFO mydb odoo.modules.registry: creating or updating database tables
...
- Restart Server odoo: docker restart <container_odoo>
- Install Python libraries by using docker exec -it <container_odoo> /bin/bash to access the container, and then running pip install
inside it.
If You see error
network internal_shared_net declared as external, but could not be found
Please create new or check your external network docker, modify in docker-compose.yml and try again
Access Odoo
Open your web browser and go to:
http://<your-server-ip>:8869
You should see the Odoo web interface:
Check git Odoo15 Docker
Like
Reply