Skip to content

Instantly share code, notes, and snippets.

@bibstha
Created June 27, 2024 08:24
Show Gist options
  • Save bibstha/9d76f1fdefe9af89626589df5b0a67ed to your computer and use it in GitHub Desktop.
Save bibstha/9d76f1fdefe9af89626589df5b0a67ed to your computer and use it in GitHub Desktop.
Ruby Jupyter Notebook with persistent gems folder and jupyter token
services:
jupyter:
build: .
image: bibstha/datascience-notebook
ports:
- 80:8888
environment:
GEM_HOME: /home/jovyan/.gems
RUBYLIB: /home/jovyan/.gems
JUPYTER_TOKEN: this-is-my-token
volumes:
- jupyter-data:/home/jovyan/work
- ./gems_cache:/home/jovyan/.gems
volumes:
jupyter-data:
name: jupyter-data
# I tried creating a named volume for gems but it was being mounted as root and the user is jovyan (no write permission)
# so I did `cd path-to-docker-compose && chown 1000:100 ./gems_cache`
# GEM_HOME makes it so that `gem install xyz` will install it to `/home/jovyan/.gems`
# RUBYLIB appends the folder to $LOAD_PATH so anything installed on GEM_HOME is loaded properly
# I also had to remove the .gemrc as I wanted gems to be installed into GEM_HOME. Therefore the custom Dockerfile below.
FROM rubydata/datascience-notebook
RUN rm /home/jovyan/.gemrc
@bibstha
Copy link
Author

bibstha commented Jun 27, 2024

Put both docker-compose.yml and Dockerfile in a folder.
Run docker-compose up -d

Then open localhost:80 and enter token this-is-my-token. If you get permission error, try changing ports to 8080:8080 and load localhost:8080.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment