Jesús Furió
Jesús Furió

Reputation: 13

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

Docker compose doesn't recognize an echo command.

Recently I added the command:

echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '[email protected]', '2222bbbb')" | python manage.py shell

Compose code:

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', '[email protected]', '2222bbbb')" | python manage.py shell && python manage.py test"
        depends_on:
            - postgres

When i execute this compose Django finished with next message:

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 doesn't recognize the echo command

Upvotes: 1

Views: 47

Answers (1)

Bedilbek
Bedilbek

Reputation: 899

You did not escape double quotes inside a command as you are using them two times. The second time you are using the double quotes they should be escaped, otherwise, it will be just ending of the previous one.

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', '[email protected]', '2222bbbb')\" | python manage.py shell && python manage.py test"

Upvotes: 1

Related Questions