docker 为什么 Django -达芙妮不和多克合作

k7fdbhmy  于 2022-11-03  发布在  Docker
关注(0)|答案(2)|浏览(112)

我有一个本地和生产docker-compose服务为我的django应用程序,在本地服务都是正确的,但在生产服务daphne不工作,在相同的redis连接是平等的,我没有使用一个特殊的网络配置为我的docker-compose服务。
本地 composer :

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没有工作)

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:

错误为:

Error trying to receive messages: Error -2 connecting to redis:6379. Name or service not known.
ztmd8pv5

ztmd8pv51#

请尝试使用networks关键字,而不是links
https://docs.docker.com/compose/compose-file/#links

flvtvl50

flvtvl502#

我的修复程序正在调整docker-compose中的工作目录

working_dir: /the_name_of_your_django_project/

相关问题