Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

647
Views
127.0.0.1 refused to connect in docker django

I'm trying to connect to an instance of django running in docker. As far as i can tell I've opened the correct port, and see in docker ps that there is tcp on port 8000, but it there is no forwarding to the port.

After reading the docker compose docs on ports, i would expect this to work (I can view pgadmin on 127.0.0.1:9000 too).

My docker compose:

version: '3'

services:
  postgresql:
    restart: always
    image: postgres:latest
    environment:
      POSTGRES_USER: pguser
      POSTGRES_PASSWORD: pgpassword
      POSTGRES_DB: pgdb

  pgadmin:
    restart: always
    image: dpage/pgadmin4:latest
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
      GUNICORN_THREADS: 4
      PGADMIN_LISTEN_PORT: 9000
    volumes:
      - ./utility/pgadmin4-servers.json:/pgadmin4/servers.json 
    depends_on:
      - postgresql
    ports:
      - "9000:9000"

  app:
    build: .
    environment:
      POSTGRES_DB: pgdb
      POSTGRES_USER: pguser
      POSTGRES_PASSWORD: pgpassword
      POSTGRES_HOST: postgresql
    volumes:
      - .:/code
    ports:
      - "127.0.0.1:8000:8000"
      - "5555:5555"
    depends_on:
      - postgresql
      - pgadmin

I have tried with the following combinations for (app) ports, as are suggested here:

app:
  ...
  ports:
    - "8000"
    - "8000:8000"
    - "127.0.0.1:8000:8000"

but i still see This site can’t be reached 127.0.0.1 refused to connect. on trying to access the site.

I'm sure that this is a port forwarding problem, and that my server is turning correctly in django because i can run a docker attach to the container and curl a url with the expected response.

What am i doing wrong?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I was running my application using the command:

docker-compose run app python3 manage.py runserver 0.0.0.0:8000

With docker-compose you need to use the argument --service-ports to:

Run command with the service's ports enabled and mapped to the host.

Thus my final command looked like this:

docker-compose run --service-ports app python3 manage.py runserver 0.0.0.0:8000

Documentation on run can be found here

over 4 years ago · Santiago Trujillo Report

0

If you are running docker inside a virtual machine then you need to access your application through the virtual machine IP address and not using localhost or 127.0.0.1. Try to get the virtual machine IP. Also please specify in which platform/environment you installed and running the docker.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!