Skip to content

Instantly share code, notes, and snippets.

@manics
Last active September 19, 2021 14:44
Show Gist options
  • Save manics/c88f5f2cebadf7f0997e04f543389173 to your computer and use it in GitHub Desktop.
Save manics/c88f5f2cebadf7f0997e04f543389173 to your computer and use it in GitHub Desktop.
BinderHub in Docker

BinderHub in Docker

Run a standalone BinderHub in Docker.

This requires Docker-in-Docker so repo2docker and DockerSpawner can work.

Build

docker build -t binderhub .

Run

Replace <DOCKER-HOST-EXTERNAL-IP> with the IP of the Docker host that will be used to access BinderHub.

docker run -it --name binderhub \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 8000:8000 \
    -e JUPYTERHUB_EXTERNAL_URL=http://<DOCKER-HOST-EXTERNAL-IP>:8000/ \
    binderhub

Go to http://<DOCKER-HOST-EXTERNAL-IP>:8000 to access BinderHub.

FROM condaforge/mambaforge:4.10.3-5
RUN mamba install -y -q \
`# https://github.com/jupyterhub/binderhub/blob/c131d73537628ba2f9a635ea63a36ef5e5a0e421/requirements.txt#L1-L20` \
docker-py \
escapism \
jinja2 \
jsonschema \
jupyterhub \
kubernetes \
prometheus_client \
python-json-logger \
"tornado>=5.1" \
traitlets \
"pyjwt>=2" \
pycurl \
`# Extra requirements for BinderHub in Docker` \
dockerspawner==12.1.0 \
"jupyter-repo2docker>=2021.08.0" \
nodejs \
pip
RUN git clone https://github.com/jupyterhub/binderhub
RUN cd binderhub && \
pip install \
nullauthenticator \
.
# Run as root so we have access to the host-mounted docker socket
WORKDIR /srv/jupyterhub
RUN cp /binderhub/testing/local-binder-local-hub/jupyterhub_config.py /binderhub/testing/local-binder-local-hub/binderhub_config.py .
# Needed because we're running Docker in Docker
# https://github.com/jupyterhub/dockerspawner/blob/12.1.0/dockerspawner/dockerspawner.py#L667-L678
RUN echo "c.DockerSpawner.use_internal_ip = True" >> /srv/jupyterhub/jupyterhub_config.py
EXPOSE 8000
CMD ["jupyterhub", "--config=jupyterhub_config.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment