相关疑难解决方法(0)

使用django的Docker-compose无法将主机名"db"转换为地址:名称或服务未知

我目前使用docker-compose构建了一个系统,它创建了一个Django应用程序.

到目前为止,我在我的测试版本中使用了容器内的数据库(postgresql).现在我已将数据库从此容器更改为AWS中的RDS实例.

使用Pg_dump我在RDS中重新创建了数据库并更改了settings.py,一切都被认为是正常的.我已经从webapp中的数据库中访问了数据而没有任何问题.

一切都很好,直到我不得不进行迁移.没有数据库容器Django容器给我这样的消息:

django.db.utils.OperationalError:无法将主机名"db"转换为地址:名称或服务未知

我的Docker-compose.yml文件在更改之前:

 version: '2'

    services:
      db:
        image: postgres:9.5
        restart: always
        environment:
          POSTGRES_USER: testing
          POSTGRES_PASSWORD: tests
          POSTGRES_DB: test
        volumes:
          - /dbdata:/var/lib/postgresql/data
      django:
        build: ./django
        command: gunicorn contactto.wsgi:application -b 0.0.0.0:8000
        restart: always
        volumes:
          - ./django:/usr/src/app
          - ./django/static:/usr/src/app/contactto/static
        ports:
          - "8000:8000"
        depends_on:
          - db
Run Code Online (Sandbox Code Playgroud)

现在改变之后:

    version: '2'

    services:
      django:
        build: ./django
        command: gunicorn contactto.wsgi:application -b 0.0.0.0:8000
        restart: always
        volumes:
          - ./django:/usr/src/app
          - ./django/static:/usr/src/app/contactto/static
        ports:
          - "8000:8000"
Run Code Online (Sandbox Code Playgroud)

来自settings.py的DATABASES.之前:

DATABASES = {
        'default': {
            'ENGINE': 'tenant_schemas.postgresql_backend',
            'NAME': 'testing',
            'USER': 'test',
            'PASSWORD': …
Run Code Online (Sandbox Code Playgroud)

django postgresql amazon-web-services docker-compose

12
推荐指数
3
解决办法
1万
查看次数