Reputation: 129
I am new to Docker and I am trying to dockerize an application for the first time by following a variety of tutorials on the internet and I'm getting this error that I am unable to resolve.
I searched around, tried different things but have not found something that would help me resolve the problem.
ERROR MESSAGE : Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
Here is my docker-compose file. The error comes from jobsite.
jobsite:
container_name: job_startup
build: .
# command: ["./docker_compose/django/wait_for_postgres.sh"]
volumes:
- .:/code
environment:
PRODUCTION: 'False'
ports:
- "8000:8000"
# depends_on:
# - "db"
# links:
# - "db"
enginx:
build: ./nginx
container_name: job_nginx
restart: always
environment:
- NGINX_PORT=80
ports:
- "80:80"
depends_on:
- "jobsite"
Here is the main Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
EXPOSE 8000
CMD python manage.py runserver 0.0.0.0:8000
The screenshot of the error message:
UPDATE
db:
# image: postgres:latest
build: ./database
container_name: postgres_database
# ports:
# - "8000:5432"
restart: always
environment:
- DOCKER=True
- POSTGRES_USER=postgres
- POSTGRES_DB=jobs_data1
- POSTGRES_PASSWORD=''
- POSTGRES_HOST=127.0.0.1
- DB_USER=john
- DB_PASSWORD=''
- DB_DATABASE=jobs_data1
volumes:
- ./postgres_database:/docker-entrypoint-initdb.d/
- postgres_data:/var/lib/postgresql/data/
Upvotes: 6
Views: 7551
Reputation: 51
The application job_startup
tries to connect to a postgres database running on localhost.
Your docker-compose file is missing the db
service. Also the connection string in your python script should be db
as hostname, as described by your commented out links
and depends_on
lines.
Upvotes: 2
Reputation: 1816
Your application tries to connect to PostgreSQL running on localhost. PostgreSQL, though, is obviously not running on localhost. You'll have to add a container to your docker compose configuration that starts PostgreSQL. Then, configure your Python application to use that name instead of localhost
.
Upvotes: 3