It seems my docker-compose commands only execute the last command. In this case runserver.
command: python3 manage.py collectstatic --noinput
command: python3 manage.py migrate --noinput
command: python3 manage.py runserver 0.0.0.0:8000
I tried to move these commands into an entrypoint.sh file. However, I can't figure out how to implement this into my dockerfile & docker-compose.
The following is my dockerfile:
# Pull base image
FROM python:3
# Set environment varibles
ENV PYTHONUNBUFFERED 1
# Set work directory
RUN mkdir /code
WORKDIR /code
# Install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /code/Pipfile
RUN pipenv install --deploy --system --skip-lock --dev
# Copy project
COPY . /code/
My docker-compose:
version: '3'
services:
db:
image: postgres
ports:
- "5432:5432"
web:
build: .
command: python3 manage.py collectstatic --noinput
command: python3 manage.py migrate --noinput
command: python3 manage.py runserver 0.0.0.0:8000
env_file: .env
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
entrypoint.sh
#!/bin/bash
# Collect static files
echo "Collect static files"
python manage.py collectstatic --noinput
# Apply database migrations
echo "Apply database migrations"
python manage.py migrate
# Start server
echo "Starting server"
python manage.py runserver 0.0.0.0:8000