Skip to content

Instantly share code, notes, and snippets.

@kjagiello
Last active February 1, 2021 09:46
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kjagiello/89f186242a5749caecb8ff16961f013d to your computer and use it in GitHub Desktop.
Save kjagiello/89f186242a5749caecb8ff16961f013d to your computer and use it in GitHub Desktop.
An example Dockerfile showing how to build Facebook's watchman for your application (a life saver when running Django locally)

Do you develop a Django application locally using docker on MacOS? Have you ever experienced that is killing your CPU and battery? The reason for that is that Django constantly polls all the project files looking for changes and this, in combination with all the abstraction layers for the Docker storage on MacOS, causes this issue. Luckily, Django 2.2+ has built-in support for Watchman which provides cross-platform support for efficent file monitoring mechanisms. Below you will find a multi-stage Dockerfile showing how to build Watchman and integrate it into your application image.

# Stage: watchman
# Build watchman as a separate stage in the build process, as we do not want
# all the build dependencies to end up in the final image.
FROM python:3.7 AS watchman
ARG WATCHMAN_VERSION=v4.9.0
ENV WATCHMAN_VERSION=${WATCHMAN_VERSION}
WORKDIR /tmp
RUN apt update && apt install -y \
build-essential libssl-dev autoconf automake libtool pkg-config git
RUN git clone --branch ${WATCHMAN_VERSION} https://github.com/facebook/watchman.git && \
cd watchman/ && \
./autogen.sh && \
./configure --without-python --enable-lenient && \
make && \
make install
# Stage: app
FROM python:3.7
# Install watchman built in the previous stage.
COPY --from=watchman /usr/local/bin/watchman /usr/local/bin/watchman
RUN mkdir -m g+s -p /usr/local/var/run/watchman
# Install dependencies, set up project, etc. Remember to install a watchman client,
# e.g. pywatchman for Python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment