How to specify a custom Dockerfile¶
To specify a custom Dockerfile that will be used to build your application you should go to application settings, and on the first tab "Build Settings"
Select Custom Dockerfile from the list
The text field "Custom Dockerfile" will appear under the dropdown.
In this text field put the Dockerfile.
Directory structure:¶
During the build Dockerfiles are executed in the context of a directory, one level higher than your code.
On the server structure of an application directory looks like this:
# ls /home/app/someapp
Dockerfile
code
docker-compose.yml
env/dot.env
env/envs_export.sh
The Dockerfile
will contain whatever you will pick - custom or predefined.
code
is the working copy of your app's git repo.
docker-compose.yml
is assembled from the processes enabled in the dashboard in Processes
tab.
env/dot.env
are env variables in the dotenv format, for example:
DJANGO_COLLECTSTATIC=1
DJANGO_DEBUG=False
DJANGO_ALLOWED_HOSTS=something.applikuapp.com
This file is used in docker-compose.yml
env/envs_export.sh
also contains environment variables, but in a different format:
export DJANGO_COLLECTSTATIC="1"
export DJANGO_DEBUG="False"
export DJANGO_ALLOWED_HOSTS="something.applikuapp.com"
This file may be used in dockerfile if you need environment variables during the build.
In order to write your own Dockerfile make sure you COPY
your project files from /code
, not from .
Predefined Dockerfiles¶
Here are the list of some predefined Dockerfiles which you can grab and customize to your project's needs.
Python-3.12 Dockerfile¶
FROM python:3.12.0-bullseye
SHELL ["/bin/bash", "-c"]
ENV PIP_NO_CACHE_DIR off
ENV PIP_DISABLE_PIP_VERSION_CHECK on
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 0
RUN apt-get update \
&& apt-get install -y --force-yes \
nano python3-pip gettext chrpath libssl-dev libxft-dev \
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev\
&& rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip && pip install gunicorn psycopg2-binary mysqlclient
WORKDIR /code/
COPY ./code/requirements.txt /code/
RUN pip install -r requirements.txt
COPY ./code/ /code/
COPY ./env/ /env/
RUN source /env/envs_export.sh && if [ -n "$BUILD_COMMAND" ]; then eval $BUILD_COMMAND; fi
RUN source /env/envs_export.sh && export && if [ -f "manage.py" ]; then if [ "$DISABLE_COLLECTSTATIC" == "1" ]; then echo "collect static disabled"; else echo "Found manage.py, running collectstatic" && python manage.py collectstatic --noinput; fi; else echo "No manage.py found. Skipping collectstatic."; fi;
RUN useradd -ms /bin/bash code
USER code
Python-3.12 + Node 20 NPM Dockerfile¶
Let's look how the predefined Dockerfile for python 3.12 + Node 20 NPM looks like:
FROM python:3.12.0-bullseye
SHELL ["/bin/bash", "-c"]
ENV PIP_NO_CACHE_DIR off
ENV PIP_DISABLE_PIP_VERSION_CHECK on
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 0
RUN apt-get update \
&& apt-get install -y --force-yes \
nano python3-pip gettext chrpath libssl-dev libxft-dev \
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev\
&& rm -rf /var/lib/apt/lists/*
ENV NODE_VERSION=20.10.0
ENV NVM_DIR=/root/.nvm
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.7/install.sh | bash
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version
RUN npm install --global yarn@1.22.21
RUN pip install --upgrade pip && pip install gunicorn psycopg2-binary mysqlclient
WORKDIR /code/
COPY ./code/requirements.txt /code/
RUN pip install -r requirements.txt
COPY ./code/ /code/
COPY ./env/ /env/
RUN source /env/envs_export.sh && if [ -n "$BUILD_COMMAND" ]; then eval $BUILD_COMMAND; fi
RUN source /env/envs_export.sh && export && if [ -f "manage.py" ]; then if [ "$DISABLE_COLLECTSTATIC" == "1" ]; then echo "collect static disabled"; else echo "Found manage.py, running collectstatic" && python manage.py collectstatic --noinput; fi; else echo "No manage.py found. Skipping collectstatic."; fi;
RUN useradd -ms /bin/bash code
USER code
Node 20 NPM Dockerfile¶
FROM node:20-alpine
RUN apk add --no-cache libc6-compat build-base python3
WORKDIR /code
COPY code/package*.json ./
RUN npm install
COPY code/. .
COPY ./code/ /code/
COPY ./env/ /env/
RUN source /env/envs_export.sh && if [ -n "$BUILD_COMMAND" ]; then eval $BUILD_COMMAND; fi