簡體   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