My Digital Garden

Devcontainer spec for Jupyter Notebooks

Devcontainer spec for Jupyter Notebooks

Add the following files to your workspace:

./.devcontainer/devcontainer.json

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers-community/templates/tree/main/src/jupyter-datascience-notebooks
{
	"name": "Jupyter Data Science Notebooks",
	"build": {
		"dockerfile": "Dockerfile"
	},
	// Features to add to the dev container. More info: https://containers.dev/features.
	"features": {
		"ghcr.io/devcontainers/features/common-utils:2": {
			"installZsh": "true",
			"username": "jovyan",
			"userUid": "1000",
			"userGid": "1000",
			"upgradePackages": "true"
		}
	},
	// Use base images default CMD.
	"overrideCommand": false,
	// Forward Jupyter port locally, mark required.
	"forwardPorts": [8888],
	"portsAttributes": {
		"8888": {
			"label": "Jupyter",
			"requireLocalPort": true,
			"onAutoForward": "ignore"
		}
	},
	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": {
				"python.defaultInterpreterPath": "/opt/conda/bin/python"
			},
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": ["ms-python.python", "ms-toolsai.jupyter"]
		}
	}
	// Use 'postCreateCommand' to run commands after the container is created.
	// "postCreateCommand": "pip3 install --user -r requirements.txt",

	// Configure tool-specific properties.
	// "customizations": {},

	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

./.devcontainer/Dockerfile

FROM docker.io/jupyter/datascience-notebook:latest

USER root
# Generally, Dev Container Features assume that the non-root user (in this case jovyan)
# is in a group with the same name (in this case jovyan). So we must first make that so.
RUN groupadd jovyan \
    && usermod -g jovyan -a -G users jovyan

USER jovyan

Remarks

Also works in GitHub CodeSpaces

See also