We love to see the community create and share new Jupyter Docker images. We’ve put together a cookiecutter project and the documentation below to help you get started defining, building, and sharing your Jupyter environments in Docker. Following these steps will:
Setup a project on GitHub containing a Dockerfile based on either the
Configure GitHub Actions to build and test your image when users submit pull requests to your repository.
Configure Docker Hub to build and host your images for others to use.
Update the list of community stacks in this documentation to include your image.
This approach mirrors how we build and share the core stack images. Feel free to follow it or pave your own path using alternative services and build tools.
Creating a Project¶
First, install cookiecutter using pip or conda:
pip install cookiecutter # or mamba install cookiecutter
Run the cookiecutter command pointing to the jupyter/cookiecutter-docker-stacks project on GitHub.
Enter a name for your new stack image. This will serve as both the git repository name and the part of the Docker image name after the slash.
Enter the user or organization name under which this stack will reside on Docker Hub. You must have access to manage this Docker Hub organization to push images here and set up automated builds.
Select an image from the jupyter/docker-stacks project that will serve as the base for your new image.
Enter a longer description of the stack for your README.
stack_description [my-jupyter-stack is a community maintained Jupyter Docker Stack image]:
Initialize your project as a Git repository and push it to GitHub.
cd <stack_name you chose> git init git add . git commit -m 'Seed repo' git remote add origin <url from github> git push -u origin master
Configuring GitHub actions¶
The cookiecutter template comes with a
.github/workflows/docker.yml file, which allows you to use GitHub actions to build your Docker image whenever you or someone else submits a pull request.
By default the
.github/workflows/docker.yamlfile has the following triggers configuration:
on: pull_request: paths-ignore: - "*.md" push: branches: - main - master paths-ignore: - "*.md"
This will trigger the CI pipeline whenever you push to your
masterbranch and when any Pull Requests are made to your repository. For more details on this configuration, visit the GitHub actions documentation on triggers.
Commit your changes and push to GitHub.
Head back to your repository and click on the Actions tab. From there, you can click on the workflows on the left-hand side of the screen.
In the next screen, you will be able to see information about the workflow run and duration. If you click again on the button with the workflow name, you will see the logs for the workflow steps.
Configuring Docker Hub¶
Now, configure Docker Hub to build your stack image and push it to Docker Hub repository whenever you merge a GitHub pull request to the master branch of your project.
Visit https://hub.docker.com/ and log in.
Select the account or organization matching the one you entered when prompted with
stack_orgby the cookiecutter.
Scroll to the bottom of the page and click Create repository.
Enter the name of the image matching the one you entered when prompted with
stack_nameby the cookiecutter.
Enter a description for your image.
Click GitHub under the Build Settings and follow the prompts to connect your account if it is not already connected.
Select the GitHub organization and repository containing your image definition from the dropdowns.
Click the Create and Build button.
Click on your avatar on the top-right corner and select Account settings.
Click on Security and then click on the New Access Token button.
Enter a meaningful name for your token and click on Create
Copy the personal access token displayed on the next screen. Note that you will not be able to see it again after you close the pop-up window.
Head back to your GitHub repository and click on the Settings tab.
Click on the Secrets section and then on the New repository secret button on the top right corner (see image above).
Create a DOCKERHUB_TOKEN secret and paste the Personal Access Token from DockerHub in the value field.
Repeat the above step but creating a DOCKERHUB_USERNAME and replacing the value field with your DockerHub username. Once you have completed these steps, your repository secrets section should look something like this:
Defining Your Image¶
Make edits to the Dockerfile in your project to add third-party libraries and configure Jupyter applications. Refer to the Dockerfiles for the core stacks (e.g., jupyter/datascience-notebook) to get a feel for what’s possible and best practices.
Submit pull requests
to your project repository on GitHub.
Ensure your image builds correctly on GitHub actions before merging to
master or main.
Refer to Docker Hub to build your master or main branch that you can