6π
So you are trying to reach the db which is running in one container from another container? If yes β the following could potentially help, at least it helped me when I had similar issues.
Try to define networks config in addition to links in your compose file, create a network with some name and define it in both services. Like described here, as the docks on links config recommend to do that.
Something like this for your case:
version: '3'
services:
db:
image: 'postgres'
ports:
- '5432'
networks:
some_network:
core:
build:
context: .
dockerfile: Dockerfile
command: python3 manage.py runserver 0.0.0.0:8000
ports:
- '8000:8000'
volumes:
- .:/code
depends_on:
- db
links:
- db:db
networks:
some_network:
networks:
some_network:
It helped me to resolve the host name to connect to the db.
6π
Instead of redefining the networks, use
docker-compose down -v
to stop all containers and remove all cached data.
Then
docker-compose up
to restart from scratch.
- Django Foreign Key: get related model?
- TimeField format in Django template
- How can I test if my redis cache is working?
- Can we have Django DateTimeField without timezone?
- Accessing django project in LAN systems
- Is there a way to generate pdf containing non-ascii symbols with pisa from django template?
- How to concatenate two model fields in a Django QuerySet?
- How to set timeout for urlfetch in Google App Engine?
3π
Iβve been searching for several days for the solution to this issue. Hereβs what I did:
1 β I copied the postgresql.conf.sample file from my postgres container to my project folder
you must get in to cd usr/share/postgresql
with docker exec -it yourcontainer
bash
2 β I changed its name to postgresql.conf
3 β I modified these variables in postgresql.conf
listen_addresses = '*'
port = 5432
max_connections = 100
superuser_reserved_connections = 3
unix_socket_directories = '/tmp'
4 β I added it to my Dockerfile
COPY postgresql.conf /tmp/postgresql.conf
5 β settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'test',
'USER': 'testing',
'PASSWORD': 'tests',
'HOST': 'localhost',
'PORT': 5432,
}
}
6 β I did docker-compose up -build
again
- AttributeError: 'NoneType' object has no attribute 'attname' (Django)
- How can i get all models in django 1.8
- Django β Import views from separate apps
- {% load static %} and {% load staticfiles %}: which is preferred?
- Python/Django: sending emails in the background
2π
I came across this issue recently, i solved it by adding postgres environment variables to db in my docker-compose.yml file like so
version: '3'
services:
db:
image: 'postgres'
ports:
- '5432'
environment:
- POSTGRES_DB=booksdb
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
core:
build:
context: .
dockerfile: Dockerfile
command: python3 manage.py runserver 0.0.0.0:8000
ports:
- '8000:8000'
volumes:
- .:/code
depends_on:
- db
links:
- db:db
- Django template indentation guideline
- Django Newsletter App
- Remove padding from matplotlib plotting
- Django logging β django.request logger and extra context
- Why is Django's Meta an old-style class?
1π
In my specific case, I had postgres without any version, so postgres image gets updated and the db (postgres) container wonβt get up
- Django raises MultiValueDictKeyError in File Upload
- Pycharm (Python IDE) doesn't auto complete Django modules
- Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'
- How to create custom groups in django from group
- How can I test if my redis cache is working?
0π
The following configuration works for me from official documentation
version: "3.8"
services:
db:
image: postgres
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
then run those commands:
docker-compose up -d --build
docker-compose logs
- How to combine django plus gevent the basics?
- Django redirect() with anchor (#) parameters
- Assign Value of Named URL to a Variable in Django Templates
- Uwsgi segmentation fault when serving a django application
- Django queryset __contains case sensitive?
0π
docker exec -it "container_name" python3 manage.py migrate
This works for me. Make sure of the path to the manage.py file is correct.
- Is there a way to render a html page without view model?
- How can I easily convert a Django app from mySQL to PostgreSQL?
- Django β authentication, registration with email confirmation
- How to assign to a Django PointField model attribute?