Skip to content

Instantly share code, notes, and snippets.

@tedsteinmann
Last active December 16, 2020 16:55
Show Gist options
  • Save tedsteinmann/fc6412bdcc5c5aeb1b6a4c59ea0b50c4 to your computer and use it in GitHub Desktop.
Save tedsteinmann/fc6412bdcc5c5aeb1b6a4c59ea0b50c4 to your computer and use it in GitHub Desktop.
How to create Juypeter notebooks in Docker

Jupyter Notebook on Docker

This gist can be used to setup Juypter in Docker with docker compose.

Installation

  1. Clone this Gist

    git clone https://gist.github.com/fc6412bdcc5c5aeb1b6a4c59ea0b50c4.git notebooks

  2. cd notebooks

  3. Run make start

Upon sucessful start,

  1. Copy and paste the url for your notebook with the token attached, eg:

http://127.0.0.1:8888/?token=b44e...51dc

As you create notebooks they will be saved in a "notebooks" directory on your host machine.

Dependencies

This project depends on Docker and Docker-compose being installed with the daemon running.

Updating

Feel free to update requirements and re-build the image using make build -- or make start which is a combination of build and run.

version: '3.9'
services:
datascience-notebook:
build: .
ports:
- 8888:8888
container_name: jupyter_notebook
volumes:
- ./notebooks:/notebooks
FROM python:3-slim
WORKDIR /notebooks
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 8888
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
# initiated via: https://gist.github.com/prwhite/8168133
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
# Everything below is an example
build: ## Build an image file using docker-compose
docker-compose build --no-cache
run: ## Run the current image using docker-compose
docker-compose up
start: build run ## Build and run the current image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment