Django console container not get configurations from docker compose file
Hi! I'm working on a Django project using Docker and I've successfully created the Dockerfile and docker-compose.yml file. Pycharm running very well. However, I'm experiencing an issue when trying to use the Django console. The container created by the console does not seem to receive any environment variables from the docker-compose file, and even when I manually add these variables, the container is unable to connect to the database container. It seems that it is unable to find the host.
Can anyone help me with this problem?
This is the Starting Script:
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
This is my docker-compose.yml:
services:
db:
container_name: container-db
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
ports:
- "6543:5432"
environment:
- POSTGRES_DB=ticketera_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build:
context: .
dockerfile: Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
environment:
- DJANGO_SECRET_KEY={SECRET_KEY}
- DEBUG=True
...
depends_on:
- db
Please let me know if there is anything else
Please sign in to leave a comment.
Hi, does the issue reproduce in the latest PyCharm version 2022.3 ?
Are you unable to read the variable if you run this in Django console?
I have created a minimal project and the issue is not reproducible for me -- the env variables are read successfully when I look them up with os.getenv