Skip to content

DATABASE_URL is exported in django container entrypoint but not available in container #6273

@millerthegorilla

Description

@millerthegorilla

What happened?

I started my production build and execed into the django container to run a command that complains about a missing DATABASE_URL. But the DATABASE_URL is exported in the container entrypoint.sh and should be present.

What should've happened instead?

The DATABASE_URL environment variable should be available inside the docker container. At least that is what I would expect from the statement on line 11 of entrypoint.sh :

export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"

Perhaps it is either being deleted for security? or is it not occurring because some/all of the POSTGRES_ environment variables are empty at that point?
I know that I can solve this issue by creating:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "mind_survey_app",
        "USER": "postgres_debug_user",
        "PASSWORD": "....",
        "HOST": "postgres",
        "PORT": "5432",
    }
}

in the appropriate settings.py, but I think this might be a security issue for production use.
I can also place the DATABASE_URL line above into the POSTGRES .env file, and I think that works and should be secure.
Please let me know if I am wrong!!

Additional details

sudo docker compose -f docker-compose.production.yml up

  • Host system configuration:
    • Version of cookiecutter CLI (get it with cookiecutter --version): latest one, as of today.

    • OS name and version:

      # Insert here the OS name and version

Distributor ID: Ubuntu
Description: Ubuntu 24.04.3 LTS
Release: 24.04
Codename: noble
```

  • Python version, run python3 -V: - python is inside a venv inside the django container.

  • Docker version (if using Docker), run docker --version:

  • docker compose version (if using Docker), run docker compose --version:

  • Docker version 29.1.3, build f52814d

  • ...

  • Options selected and/or replay file:
    On Linux and macOS: cat ${HOME}/.cookiecutter_replay/cookiecutter-django.json
    (Please, take care to remove sensitive information)

 its on my dev vm, which I am not on currently, but standard stuff, whitenoise, vscode, github, containers, etc
Logs:
Details
$ cookiecutter https://github.com/cookiecutter/cookiecutter-django
project_name [Project Name]: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions