I currently have a system built using docker-compose, it is building a Django application.
So far, I have used the database inside the container (postgresql) in my test build. Now I changed the database from this container to an RDS instance in AWS.
Using Pg_dump I recreated the database inside RDS and changed settings.py, everything was fine. I accessed data from a database inside my webapp without any problems.
Everything was fine until I had to endure. Without a database container, the Django container gives me this message:
django.db.utils.OperationalError: failed to translate hostname "db" to: name or service unknown
My Docker-compose.yml file before the changes:
version: '2' services: db: image: postgres:9.5 restart: always environment: POSTGRES_USER: testing POSTGRES_PASSWORD: tests POSTGRES_DB: test volumes: - /dbdata:/var/lib/postgresql/data django: build: ./django command: gunicorn contactto.wsgi:application -b 0.0.0.0:8000 restart: always volumes: - ./django:/usr/src/app - ./django/static:/usr/src/app/contactto/static ports: - "8000:8000" depends_on: - db
Now after the changes:
version: '2' services: django: build: ./django command: gunicorn contactto.wsgi:application -b 0.0.0.0:8000 restart: always volumes: - ./django:/usr/src/app - ./django/static:/usr/src/app/contactto/static ports: - "8000:8000"
AND DATABASES from settings.py. Before:
DATABASES = { 'default': { 'ENGINE': 'tenant_schemas.postgresql_backend', 'NAME': 'testing', 'USER': 'test', 'PASSWORD': 'test', 'HOST': 'db', 'PORT': '5432', } }
After:
DATABASES = { 'default': { 'ENGINE': 'tenant_schemas.postgresql_backend', 'NAME': 'testing', 'USER': 'test', 'PASSWORD': 'test', 'HOST': 'xxx.rds.amazonaws.com', 'PORT': '5432', } }
Strange, I can use the aws database inside my application ... I can create users and do something inside the database, and changes appear. Now in the CLI I can’t even use the manage.py shell without a message.
I am completely lost.