gpt4 book ai didi

python - 当我添加新命令进行撰写时,Docker Compose 与 Django 错误

转载 作者:行者123 更新时间:2023-12-01 07:31:35 26 4
gpt4 key购买 nike

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"

关于python - 当我添加新命令进行撰写时,Docker Compose 与 Django 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57187230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com