繁体   English   中英

当我添加新命令来撰写时,Docker Compose出现Django错误

[英]Docker Compose with Django error when I add new command to compose

Docker compose无法识别echo命令。

最近我添加了命令:

echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', '2222bbbb')" | python manage.py shell

撰写代码:

version: '2'

services:
    postgres:
        image: postgres
        container_name: app_postgres
        environment:
            - POSTGRES_DB=postgres
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres

    django:
        image: python:3.6.8
        container_name: app_django
        environment:
            - DJANGO_SETTINGS_MODULE=project.settings_staging
            - POSTGRES_DB=postgres
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
            - POSTGRES_HOST=postgres
        working_dir: /code
        volumes:
            - ./:/code
            - ./requirements.txt:/code/requirements.txt
        ports:
            - 6000:8000
        command: bash -c "pip install -r requirements.txt && python manage.py migrate --noinput && echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', '2222bbbb')" | python manage.py shell && python manage.py test"
        depends_on:
            - postgres

当我执行此撰写时,Django完成下一条消息:

app_django |   Apply all migrations: account, admin, auth, authtoken, contenttypes, filters, sessions, sites, users
app_django | Running migrations:
app_django |   No migrations to apply.
app_django | from
app_django exited with code 0

Django无法识别echo命令

您没有在命令中使用双引号,因为您使用了两次。 第二次使用双引号时,应将其转义,否则,它将只是前一个引号的结尾。

command: bash -c "pip install -r requirements.txt && python manage.py migrate --noinput && echo \"from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', '2222bbbb')\" | python manage.py shell && python manage.py test"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM