Introduction:
In this guide, I’ll walk you through the installation of Odoo 17 with PostgreSQL 16 using Docker Compose. Along the way, we’ll address several common issues that might arise, such as database password mismatches, missing roles, and how to troubleshoot PostgreSQL authentication failures.
By the end of this article, you’ll have a fully functional Odoo 17 instance running on PostgreSQL 16, and you’ll know how to troubleshoot some of the more frustrating roadblocks.
Prerequisites:
- Docker and Docker Compose installed on your machine.
- Basic understanding of Docker containers and Docker Compose.
- Familiarity with PostgreSQL and Odoo configuration.
Steps for Installing Odoo 17 with PostgreSQL 16
Step 1: Setting up the Docker Compose Environment
First, we’ll create the docker-compose.yml
file that defines both the Odoo and PostgreSQL services.
version: '3.1'
services:
db:
image: postgres:16
healthcheck:
test: ["CMD-SHELL", "pg_isready -U odoo"]
interval: 10s
timeout: 5s
retries: 5
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=strong_db_password
volumes:
- odoo-db-data:/var/lib/postgresql/data
ports:
- "5444:5432"
restart: unless-stopped
networks:
- odoo-network
web:
image: my-custom-odoo:17
depends_on:
db:
condition: service_healthy
ports:
- "8070:8069"
volumes:
- ./config:/etc/odoo
- ./addons:/mnt/extra-addons
- odoo-web-data:/var/lib/odoo
environment:
- LANG=en_US.UTF-8
- LANGUAGE=en_US:en
- LC_ALL=en_US.UTF-8
- HOST=db
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=strong_db_password
- POSTGRES_DB=postgres
restart: unless-stopped
networks:
- odoo-network
volumes:
odoo-web-data:
odoo-db-data:
networks:
odoo-network:
driver: bridge
This configuration file sets up two services: the PostgreSQL 16 database and Odoo 17, ensuring that they run in separate containers and can communicate with each other.
Step 2: Building the Docker Image
To ensure that our Odoo instance waits for PostgreSQL to be fully ready before starting, we’ll create a custom entrypoint.
- Create
wait-for-postgres.sh
to check the database readiness:
#!/bin/bash
# wait-for-postgres.sh
set -e
host="$1"
# Wait until PostgreSQL is ready
until PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$host" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - proceeding"
- Create
custom-entrypoint.sh
for Odoo:
#!/bin/bash
set -e
# Wait for PostgreSQL to be ready
/usr/local/bin/wait-for-postgres.sh db
# Execute Odoo with any provided arguments
exec odoo "$@"
- Dockerfile to use custom entrypoint:
FROM odoo:17
# Install locales and ensure the system uses UTF-8
RUN apt-get update && apt-get install -y locales && locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
# Copy custom scripts
COPY wait-for-postgres.sh /usr/local/bin/wait-for-postgres.sh
COPY custom-entrypoint.sh /usr/local/bin/custom-entrypoint.sh
RUN chmod +x /usr/local/bin/wait-for-postgres.sh /usr/local/bin/custom-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/custom-entrypoint.sh"]
Step 3: Running the Docker Compose Stack
Once everything is set up, you can bring up your containers with:
docker compose up -d
This will start PostgreSQL and Odoo, and thanks to the custom entrypoint, Odoo will wait until PostgreSQL is ready before attempting to connect.
Common Issues & Fixes
Issue 1: PostgreSQL Password Authentication Failure
This is one of the most common issues you’ll face. The error usually looks like this:
psycopg2.OperationalError: connection to server at "db" failed: FATAL: password authentication failed for user "odoo"
Cause: The issue arises because PostgreSQL initializes with the POSTGRES_PASSWORD
environment variable only during the first initialization. If the database is already created and persisted in a volume, changing the password in docker-compose.yml
won’t update the existing password.
Solution:
- Remove the Existing Database Volume: This will reset the database and allow PostgreSQL to be reinitialized with the correct password.
docker compose down --volumes
docker compose up -d
- Or Update the PostgreSQL Password Manually:
docker compose exec db bash
su - postgres
psql
ALTER USER odoo WITH PASSWORD 'strong_db_password';
After that, restart the Odoo service:
docker compose restart web
Issue 2: Missing PostgreSQL postgres
Role
If you encounter the following error:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "postgres" does not exist
Cause: This error indicates that the postgres
user was not created during initialization.
Solution:
- Access the PostgreSQL container:
docker compose exec db bash
su - postgres
- Create the
postgres
user manually:
CREATE ROLE postgres WITH SUPERUSER LOGIN PASSWORD 'strong_password';
This should resolve the missing postgres
role issue.
Conclusion
Installing Odoo 17 with PostgreSQL 16 using Docker Compose can be fairly straightforward, but as with most setups, issues can arise—especially when it comes to database connections and password authentication. Fortunately, these issues can be resolved with the steps outlined above.
Whether you’re troubleshooting password mismatches or missing roles, this guide provides a comprehensive path to getting your Odoo instance up and running smoothly.
If you run into additional issues, always check the logs first (docker compose logs web
), as they can give you clear hints about what’s going wrong.
Next Steps
Now that your Odoo 17 installation is working, you can start exploring the powerful capabilities of Odoo or customize it further to fit your business needs.
Feel free to reach out with any questions or share your own tips and tricks for installing Odoo in the comments below.
Tags:
Odoo 17
, PostgreSQL 16
, Docker
, Troubleshooting
, Installation
This blog post addresses common installation issues and provides solutions for successfully setting up Odoo 17 with PostgreSQL 16, helping readers overcome roadblocks they might encounter during the process.
Let me know if you’d like to tweak anything, or if you’d like further details on specific parts!