Skip to Content
Menu
This question has been flagged

Hi,


I'm currently using the Odoo 17 docker image and would like to set the admin_passwd config value using environment variables.


  1. I've tried but do]esn't seem to work. Can ayone confirm if this is possible? 
  2. If it isn't, what options do I have or how can I "merge" odoo.conf files?

Thanks!

Avatar
Discard
Best Answer

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:

  1. Set Environment Variable in Docker:
    • Define the environment variable in your docker-compose.yml or when running the container:
      environment:
        - ADMIN_PASSWORD=my_secure_password
      
  2. 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 "$@"
    
  3. Rebuild and Run the Container:
    • Build the custom image:
      docker build -t custom-odoo .
      
    • Run the container with the environment variable:
      docker run -e ADMIN_PASSWORD=my_secure_password custom-odoo
      

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:

  1. 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 "$@"
    
  2. 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"]
    
  3. 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:

  1. 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
    
  2. Modify the Entrypoint:
    • Use the --config option to load multiple configuration files.
    • For example:
      odoo --config=/etc/odoo/base.conf --config=/etc/odoo/admin.conf
      
  3. Automate This with Docker:
    • Copy multiple configuration files into the container:
      volumes:
        - ./base.conf:/etc/odoo/base.conf
        - ./admin.conf:/etc/odoo/admin.conf
      
    • Modify the CMD or entrypoint to include the merged configuration.

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:

  1. Create a Secret:
    echo "my_secure_password" | docker secret create odoo_admin_password -
    
  2. Update docker-compose.yml:
    services:
      odoo:
        image: odoo:17
        secrets:
          - odoo_admin_password
    secrets:
      odoo_admin_password:
        file: /run/secrets/odoo_admin_password
    
  3. Update the Entrypoint Script:
    • Read the secret file and add it to odoo.conf:
      if [ -f /run/secrets/odoo_admin_password ]; then
          ADMIN_PASSWORD=$(cat /run/secrets/odoo_admin_password)
          echo "admin_passwd = $ADMIN_PASSWORD" >> /etc/odoo/odoo.conf
      fi
      
      exec "$@"
      

5. Verify the Setup

After implementing the changes, verify that the admin password is set correctly:

  1. Log in to Odoo.
  2. Go to Settings > Activate Developer Mode > General Settings.
  3. 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!

Avatar
Discard
Best Answer

Not sure what version Gracious Joseph used, but using multiple conf files with something like

odoo --config=/etc/odoo/base.conf --config=/etc/odoo/admin.conf

definitely does not work in Odoo 18. It will always use the last conf file provided

Avatar
Discard
Related Posts Replies Views Activity
0
May 25
305
2
Apr 25
284
0
Apr 25
282
1
Apr 25
690
0
Mar 25
518