In Odoo, setting the admin_passwd value using environment variables in a Dockerized setup is not directly supported out of the box. However, you can work around this limitation using the following methods:
1. Use Environment Variables with the Docker Image
The Odoo Docker image does not natively support environment variables to directly configure admin_passwd. However, you can achieve this by modifying the entrypoint script or dynamically injecting the value into the odoo.conf file.
Steps:
-
Set Environment Variable in Docker:
-
Modify the Entrypoint Script:
- Extend the official Odoo Docker image by creating a custom entrypoint script that writes the environment variable into the odoo.conf file.
Example Dockerfile:
FROM odoo:17
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["odoo"]
Example entrypoint.sh:
#!/bin/bash
# Add the admin_passwd value to the odoo.conf file
if [ -n "$ADMIN_PASSWORD" ]; then
echo "admin_passwd = $ADMIN_PASSWORD" >> /etc/odoo/odoo.conf
fi
# Execute the original entrypoint command
exec "$@"
-
Rebuild and Run the Container:
2. Alternative: Dynamically Update odoo.conf
If you don’t want to modify the Docker image, you can dynamically write the environment variable into the odoo.conf file during container startup.
Steps:
-
Mount a Script to Modify odoo.conf:
- Write a script that reads the ADMIN_PASSWORD environment variable and appends it to /etc/odoo/odoo.conf.
Example script set_admin_password.sh:
#!/bin/bash
if [ -n "$ADMIN_PASSWORD" ]; then
echo "admin_passwd = $ADMIN_PASSWORD" >> /etc/odoo/odoo.conf
fi
exec "$@"
-
Add the Script in docker-compose.yml:
services:
odoo:
image: odoo:17
environment:
- ADMIN_PASSWORD=my_secure_password
volumes:
- ./set_admin_password.sh:/usr/local/bin/set_admin_password.sh
entrypoint: ["bash", "/usr/local/bin/set_admin_password.sh"]
-
Run the Container:
- The script will dynamically update odoo.conf before the container starts.
3. Combine odoo.conf Files
If you want to merge configuration files, you can copy multiple configuration files into the container and specify which files to include.
Steps:
-
Create Multiple conf Files:
- Create a base configuration file (e.g., base.conf) and an additional file for the admin password (e.g., admin.conf).
Example admin.conf:
[options]
admin_passwd = my_secure_password
-
Modify the Entrypoint:
-
Automate This with Docker:
4. Use a Secret Management Tool
For production, storing sensitive information like admin_passwd in plain text environment variables is not recommended. Use a secret management tool like Docker Secrets or HashiCorp Vault.
Using Docker Secrets:
-
Create a Secret:
echo "my_secure_password" | docker secret create odoo_admin_password -
-
Update docker-compose.yml:
services:
odoo:
image: odoo:17
secrets:
- odoo_admin_password
secrets:
odoo_admin_password:
file: /run/secrets/odoo_admin_password
-
Update the Entrypoint Script:
5. Verify the Setup
After implementing the changes, verify that the admin password is set correctly:
- Log in to Odoo.
- Go to Settings > Activate Developer Mode > General Settings.
- Ensure that the admin password is configured under the database management section.
Conclusion
- While Odoo doesn’t directly support setting admin_passwd via environment variables, you can achieve this by modifying the entrypoint script or dynamically appending the value to odoo.conf.
- For production environments, consider using secret management tools to enhance security. Let me know if you need further assistance!