Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

648
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda