首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么django-daphne不和docker合作?

为什么django-daphne不和docker合作?
EN

Stack Overflow用户
提问于 2020-01-04 06:23:06
回答 1查看 846关注 0票数 0

我为我的django应用程序提供了一个本地和生产docker-compose服务,在本地服务中一切正常,但在生产服务daphne中不工作,同样,redis连接是相等的,并且我没有为我的docker组合服务使用特殊的网络配置文件。

本地合成:

代码语言:javascript
复制
version: "3"
services:

    app:
        image: app
        build:
            context: .
            dockerfile: ./compose/local/Dockerfile
        environment:
            - DJANGO_SETTINGS_MODULE=psvt.settings.local
        volumes: 
            - ".:/django/"
        ports:
            - "8000:8000"
        depends_on:
            - redis
            - db
        links: 
            - redis:redis
            - db:postgres

    redis:
        image: redis
        restart: always
        expose:
            - '6379'

    daphne:
        restart: always
        image: "app:latest"
        working_dir: /django/
        command: bash -c "daphne -b 0.0.0.0 -p 8001 psvt.asgi:channel_layer"
        ports:
            - "8001:8001"
        environment:
            - REDIS_HOST=redis
            - DJANGO_SETTINGS_MODULE=psvt.settings.local
        depends_on:
            - redis
        links:
            - redis

    db:
        image: postgres:10.1-alpine
        volumes:
            - postgres_data:/var/lib/postgresql/data/
        expose: 
            - "5432"

volumes:
    postgres_data:

生产:(这里daphne没有工作)

代码语言:javascript
复制
version: "3"
services:
    app:
        image: app_production
        build:
            context: .
            dockerfile: ./compose/production/Dockerfile
        #command: bash -c "gunicorn psvt.wsgi:application --bind 0.0.0.0:8000"
        command: bash -c "./manage.py runserver"
        working_dir: /django/
        environment:
            - DJANGO_SETTINGS_MODULE=psvt.settings.production
        volumes: 
            - ".:/django/"
            - static_files:/static/
            - media_files:/media/
        ports:
            - "8000:8000"
        depends_on:
            - redis
            - db
        links: 
            - redis:redis
            - db:postgres

    daphne:
        restart: always
        image: "app_production:latest"
        working_dir: /django/
        command: bash -c "daphne -b 0.0.0.0 -p 8001 psvt.asgi:channel_layer"
        ports:
            - "8001:8001"
        environment:
            - REDIS_HOST=redis
            - DJANGO_SETTINGS_MODULE=psvt.settings.production
        depends_on:
            - redis
        links:
            - redis

    redis:
        image: redis
        restart: always
        expose:
            - '6379'

    db:
        image: postgres:10.1-alpine
        volumes:
            - postgres_data:/var/lib/postgresql/data/
        expose: 
            - "5432"

    nginx:
        build: 
            context: ./compose/nginx/
            dockerfile: ./Dockerfile
        ports:
            - 100:80
            - 5000:80
        links:
            - app:app
        volumes:
            - static_files:/static/
            - media_files:/media/
        depends_on:
            - app

volumes:
    postgres_data:
    static_files:
    media_files:

错误是:

代码语言:javascript
复制
Error trying to receive messages: Error -2 connecting to redis:6379. Name or service not known.
EN

回答 1

Stack Overflow用户

发布于 2020-07-28 02:28:30

尝试使用networks关键字而不是links

https://docs.docker.com/compose/compose-file/#links

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59586073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档