Django Project Dockerization

docker-compose.yml

version: "2"

services:
  web:
    build: "."
    ports:
      - "8000:80"
    volumes:
      - ".:/app:rw"
    command: python manage.py runserver 0.0.0.0:80

Dockerfile

FROM aldryn/base-project:py3-3.23

# System upgrade
RUN apt-get update && apt-get upgrade -yq

# Setup for ssh onto github
RUN mkdir -p /root/.ssh
ADD credentials/divio-deploy-key.pem /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "Host gitlab.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config

# Python
# we want to keep project-specific sources in the "wee" folder
ENV PYTHONPATH=/app/wee:$PYTHONPATH
COPY requirements.txt /app/
RUN pip install -r requirements.txt

# nvm environment variables
ENV NODE_VERSION=8.11.3
RUN . $NVM_DIR/nvm.sh && nvm install $NODE_VERSION

# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
COPY package.json /app/
RUN npm install

COPY . /app

RUN npm run build

RUN DJANGO_MODE=build python manage.py collectstatic --noinput