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

352
Visualizações
Docker container does not communicate with others in same docker network(bridge)

I'm trying to set the environment for web server on amazon web server. I want to use django, react, nginx and they are running on each docker container.

Belows are the command for running docker container.

sudo docker run --name django-server
  -it -d -p "8000:8000"
  --volume=$(pwd)/trello-copy-django-src:/backend/trello-copy
  django-server

sudo docker run --name nginx-server
  -d -p "80:80"
  --volumes-from react-server
  nginx-server

I did not specified a custom docker network bridge and I checked that they are on same default bridge by typing $ docker inspect bridge.

[{
  "Name": "bridge",
  ...,
  "Containers": {
    "...": { "Name": "django-server", ... },
    "...": { "Name": "react-server", ... },
    "...": { "Name": "nginx-server", ... },
  }
}]

So, I expected the react code down below works. But it worked only at my laptop, which has exactly same docker structure of aws.

...
const res = await fetch('http://127.0.0.1:8000/api/');
...

Failed to load resource: net::ERR_CONNECTION_REFUSED 127.0.0.1:8000/api/:1

What am I doing wrong?


These are codes in my settings.py file of django.

CORS_ORIGIN_ALLOW_ALL=True # only for dev
CORS_ALLOW_CREDENTIALS=True # only for dev
CORS_ORIGIN_WHITELIST = (
    'http://localhost',
    'http://localhost:3000',
)

The CORS message was App.js:10 Fetch API cannot load django-server:8000/api/. URL scheme must be "http" or "https" for CORS request..

I think it's different issue, and then django and CORS are not really problem... am I right?


I found that the 'localhost' of ajax await fetch('http://127.0.0.1:8000/api/'); means client side(browser) indeed.

Do I have to use server's public IP in there?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can't call by 127.0.0.1. Instead, you need to use name of the running container. Like this:

const res = await fetch('django-server:8000/api/');
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