Python 当我添加新命令进行合成时,Docker Compose with Django错误
Docker compose无法识别echo命令 最近,我添加了以下命令:Python 当我添加新命令进行合成时,Docker Compose with Django错误,python,django,docker,docker-compose,Python,Django,Docker,Docker 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: pos
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"
您需要在
命令中转义一些双引号:
;bash-c
参数在单词“from”后结束。如果您可以将更多内容移动到Dockerfile
(如pip install
行),并且如果您将扩展的启动序列移动到shell脚本中,则更容易理解。