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 in the "Build Settings" block click "Reveal Build Settings" button.
In the dropdown "Base Docker Image" select Custom Dockerfile.
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"
DJANGO_DEBUG="False"
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 Python-3.10 Dockerfile
Let's look how the predefined Dockerfile for python 3.10 looks like:
FROM python:3.10.1-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/*
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 && 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 source /env/envs_export.sh && if [ -n "$BUILD_COMMAND" ]; then eval $BUILD_COMMAND; fi
RUN useradd -ms /bin/bash code
USER code