Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

654
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda