【问题标题】:Django, Nginx, Docker with Postgresql on AWS ElasticBeanstalk - could not translate host name "db" to address: Name or service not knownDjango、Nginx、Docker 与 AWS ElasticBeanstalk 上的 Postgresql - 无法将主机名“db”转换为地址:名称或服务未知
【发布时间】:2023-03-04 11:22:01
【问题描述】:

我正在尝试将我的 Django 应用程序部署到 AWS ElasticBeanStalk。在我的本地计算机上使用 Docker compose 一切正常。但是当它在 AWS 上运行时,它给了我这个: Image of error

docker-compose.yml:

    version: '3'

services:
  db:
    image: postgres
    hostname: db
  app:
    build:
      context: .
      dockerfile: config/app/Dockerfile
    command: sh /config/on-container-start.sh
    hostname: app
    volumes:
      - ./app:/app
    expose:
      - "8000"
    depends_on:
      - db
  nginx:
    image: nginx:latest
    hostname: nginx
    ports:
      - "80:8000"
    volumes:
      - ./config/nginx:/etc/nginx/conf.d
    depends_on:
      - app

Nginx

# define group app
upstream app {
  # balancing by ip
  ip_hash;

  # define server app
  server app:8000;
}

# portal
server {
  # all requests proxies to app
  location / {
         proxy_pass http://app/;
    }

  # only respond to port 8000
  listen 8000;

  # domain localhost
  server_name localhost;
}

在settings.py中:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'HOST': 'db',
        'PORT': 5432,
    }
}

任何帮助将不胜感激, 谢谢

【问题讨论】:

  • 以文本形式发布错误消息

标签: django amazon-web-services docker nginx


【解决方案1】:

您尝试过link 选项吗?

所以,你的作文应该是这样的:

version: '3'

services:
  db:
    image: postgres
    hostname: db
  app:
    build:
      context: .
      dockerfile: config/app/Dockerfile
    command: sh /config/on-container-start.sh
    hostname: app
    links:
      - db
    volumes:
      - ./app:/app
    expose:
      - "8000"
    depends_on:
      - db
  nginx:
    image: nginx:latest
    hostname: nginx
    ports:
      - "80:8000"
    volumes:
      - ./config/nginx:/etc/nginx/conf.d
    depends_on:
      - app
    links:
      - app

depends on 选项用于在应用程序之前启动依赖项。

【讨论】:

  • 是的,我试过了,它仍然给我同样的错误。
猜你喜欢
  • 2021-10-16
  • 2017-12-16
  • 2020-10-03
  • 2017-05-25
  • 2019-07-31
  • 2021-08-25
  • 1970-01-01
  • 2016-03-07
  • 1970-01-01
相关资源
最近更新 更多