Skip to content

Commit 7c373f9

Browse files
committed
Simplify docker-compose example
1 parent d2bed7a commit 7c373f9

File tree

5 files changed

+43
-147
lines changed

5 files changed

+43
-147
lines changed

.env

Lines changed: 0 additions & 45 deletions
This file was deleted.

Dockerfile.jupyterhub

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@
33
ARG JUPYTERHUB_VERSION
44
FROM jupyterhub/jupyterhub-onbuild:$JUPYTERHUB_VERSION
55

6-
# Install dockerspawner, oauth, postgres
7-
RUN /opt/conda/bin/conda install -yq psycopg2=2.7 && \
8-
/opt/conda/bin/conda clean -tipsy && \
9-
/opt/conda/bin/pip install --no-cache-dir \
10-
oauthenticator==0.8.* \
11-
dockerspawner==0.9.*
6+
# Install dockerspawner, nativeauthenticator
7+
RUN python3 -m pip install --no-cache-dir \
8+
dockerspawner==12.* \
9+
jupyterhub-nativeauthenticator==1.*
1210

13-
# Copy TLS certificate and key
14-
ENV SSL_CERT /srv/jupyterhub/secrets/jupyterhub.crt
15-
ENV SSL_KEY /srv/jupyterhub/secrets/jupyterhub.key
16-
COPY ./secrets/*.crt $SSL_CERT
17-
COPY ./secrets/*.key $SSL_KEY
18-
RUN chmod 700 /srv/jupyterhub/secrets && \
19-
chmod 600 /srv/jupyterhub/secrets/*
20-
21-
COPY ./userlist /srv/jupyterhub/userlist
11+
CMD ["jupyterhub", "-f", "/srv/jupyterhub/jupyterhub_config.py"]

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ Key components of this reference deployment are:
4040
* **Host**: Runs the [JupyterHub components](https://jupyterhub.readthedocs.org/en/latest/getting-started.html#overview)
4141
in a Docker container on the host.
4242

43-
* **Authenticator**: Uses [OAuthenticator](https://github.com/jupyter/oauthenticator)
44-
and [GitHub OAuth](https://developer.github.com/v3/oauth/) to
45-
authenticate users.
43+
* **Authenticator**: Uses [Native Authenticator](https://github.com/jupyterhub/nativeauthenticator) to authenticate users.
4644

4745
* **Spawner**:Uses [DockerSpawner](https://github.com/jupyter/dockerspawner)
4846
to spawn single-user Jupyter Notebook servers in separate Docker
@@ -54,7 +52,7 @@ Key components of this reference deployment are:
5452
* **Persistence of user notebook directories**: Persists user notebook
5553
directories in Docker volumes on the host.
5654

57-
![JupyterHub single host Docker deployment](internal/jupyterhub-docker.png)
55+
<!-- ![JupyterHub single host Docker deployment](internal/jupyterhub-docker.png) -->
5856

5957

6058
## Prerequisites

docker-compose.yml

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,45 @@
22
# Distributed under the terms of the Modified BSD License.
33

44
# JupyterHub docker-compose configuration file
5-
version: "2"
5+
version: "3"
66

77
services:
8-
hub-db:
9-
image: postgres:9.5
10-
container_name: jupyterhub-db
11-
restart: always
12-
environment:
13-
POSTGRES_DB: ${POSTGRES_DB}
14-
PGDATA: ${DB_VOLUME_CONTAINER}
15-
env_file:
16-
- secrets/postgres.env
17-
volumes:
18-
- "db:${DB_VOLUME_CONTAINER}"
19-
208
hub:
21-
depends_on:
22-
- hub-db
239
build:
2410
context: .
2511
dockerfile: Dockerfile.jupyterhub
2612
args:
27-
JUPYTERHUB_VERSION: ${JUPYTERHUB_VERSION}
13+
JUPYTERHUB_VERSION: 3.0.0
2814
restart: always
2915
image: jupyterhub
3016
container_name: jupyterhub
17+
networks:
18+
- jupyterhub-network
3119
volumes:
3220
# Bind Docker socket on the host so we can connect to the daemon from
3321
# within the container
3422
- "/var/run/docker.sock:/var/run/docker.sock:rw"
3523
# Bind Docker volume on host for JupyterHub database and cookie secrets
36-
- "data:${DATA_VOLUME_CONTAINER}"
24+
- "jupyterhub-data:/data"
3725
ports:
38-
- "443:443"
39-
links:
40-
- hub-db
26+
- "8000:8000"
4127
environment:
28+
# This username will be a JupyterHub admin
29+
JUPYTERHUB_ADMIN: admin
4230
# All containers will join this network
43-
DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}
31+
DOCKER_NETWORK_NAME: jupyterhub-network
4432
# JupyterHub will spawn this Notebook image for users
45-
DOCKER_NOTEBOOK_IMAGE: ${LOCAL_NOTEBOOK_IMAGE}
33+
DOCKER_NOTEBOOK_IMAGE: jupyter/minimal-notebook:latest
4634
# Notebook directory inside user image
47-
DOCKER_NOTEBOOK_DIR: ${DOCKER_NOTEBOOK_DIR}
48-
# Using this run command (optional)
49-
DOCKER_SPAWN_CMD: ${DOCKER_SPAWN_CMD}
50-
# Postgres db info
51-
POSTGRES_DB: ${POSTGRES_DB}
52-
POSTGRES_HOST: hub-db
53-
env_file:
54-
- secrets/postgres.env
55-
- secrets/oauth.env
35+
DOCKER_NOTEBOOK_DIR: /home/jovyan/work
36+
# Using this run command
37+
DOCKER_SPAWN_CMD: start-singleuser.sh
5638
command: >
5739
jupyterhub -f /srv/jupyterhub/jupyterhub_config.py
5840
5941
volumes:
60-
data:
61-
external:
62-
name: ${DATA_VOLUME_HOST}
63-
db:
64-
external:
65-
name: ${DB_VOLUME_HOST}
42+
jupyterhub-data:
6643

6744
networks:
68-
default:
69-
external:
70-
name: ${DOCKER_NETWORK_NAME}
45+
jupyterhub-network:
46+
name: jupyterhub-network

jupyterhub_config.py

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,75 +12,52 @@
1212

1313
# Spawn single-user servers as Docker containers
1414
c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
15+
1516
# Spawn containers from this image
16-
c.DockerSpawner.container_image = os.environ['DOCKER_NOTEBOOK_IMAGE']
17+
c.DockerSpawner.image = os.environ['DOCKER_NOTEBOOK_IMAGE']
18+
1719
# JupyterHub requires a single-user instance of the Notebook server, so we
1820
# default to using the `start-singleuser.sh` script included in the
1921
# jupyter/docker-stacks *-notebook images as the Docker run command when
2022
# spawning containers. Optionally, you can override the Docker run command
2123
# using the DOCKER_SPAWN_CMD environment variable.
2224
spawn_cmd = os.environ.get('DOCKER_SPAWN_CMD', "start-singleuser.sh")
23-
c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd })
25+
c.DockerSpawner.cmd = spawn_cmd
26+
2427
# Connect containers to this Docker network
2528
network_name = os.environ['DOCKER_NETWORK_NAME']
2629
c.DockerSpawner.use_internal_ip = True
2730
c.DockerSpawner.network_name = network_name
28-
# Pass the network name as argument to spawned containers
29-
c.DockerSpawner.extra_host_config = { 'network_mode': network_name }
30-
# Explicitly set notebook directory because we'll be mounting a host volume to
31-
# it. Most jupyter/docker-stacks *-notebook images run the Notebook server as
31+
32+
# Explicitly set notebook directory because we'll be mounting a volume to it.
33+
# Most jupyter/docker-stacks *-notebook images run the Notebook server as
3234
# user `jovyan`, and set the notebook directory to `/home/jovyan/work`.
3335
# We follow the same convention.
3436
notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'
3537
c.DockerSpawner.notebook_dir = notebook_dir
38+
3639
# Mount the real user's Docker volume on the host to the notebook user's
3740
# notebook directory in the container
3841
c.DockerSpawner.volumes = { 'jupyterhub-user-{username}': notebook_dir }
39-
# volume_driver is no longer a keyword argument to create_container()
40-
# c.DockerSpawner.extra_create_kwargs.update({ 'volume_driver': 'local' })
42+
4143
# Remove containers once they are stopped
42-
c.DockerSpawner.remove_containers = True
44+
c.DockerSpawner.remove = True
45+
4346
# For debugging arguments passed to spawned containers
4447
c.DockerSpawner.debug = True
4548

4649
# User containers will access hub by container name on the Docker network
4750
c.JupyterHub.hub_ip = 'jupyterhub'
4851
c.JupyterHub.hub_port = 8080
4952

50-
# TLS config
51-
c.JupyterHub.port = 443
52-
c.JupyterHub.ssl_key = os.environ['SSL_KEY']
53-
c.JupyterHub.ssl_cert = os.environ['SSL_CERT']
54-
55-
# Authenticate users with GitHub OAuth
56-
c.JupyterHub.authenticator_class = 'oauthenticator.GitHubOAuthenticator'
57-
c.GitHubOAuthenticator.oauth_callback_url = os.environ['OAUTH_CALLBACK_URL']
58-
5953
# Persist hub data on volume mounted inside container
60-
data_dir = os.environ.get('DATA_VOLUME_CONTAINER', '/data')
61-
62-
c.JupyterHub.cookie_secret_file = os.path.join(data_dir,
63-
'jupyterhub_cookie_secret')
54+
c.JupyterHub.cookie_secret_file = '/data/jupyterhub_cookie_secret'
55+
c.JupyterHub.db_url = "sqlite:////data/jupyterhub.sqlite"
6456

65-
c.JupyterHub.db_url = 'postgresql://postgres:{password}@{host}/{db}'.format(
66-
host=os.environ['POSTGRES_HOST'],
67-
password=os.environ['POSTGRES_PASSWORD'],
68-
db=os.environ['POSTGRES_DB'],
69-
)
57+
# Authenticate users with Native Authenticator
58+
c.JupyterHub.authenticator_class = 'nativeauthenticator.NativeAuthenticator'
7059

71-
# Whitlelist users and admins
72-
c.Authenticator.whitelist = whitelist = set()
73-
c.Authenticator.admin_users = admin = set()
74-
c.JupyterHub.admin_access = True
75-
pwd = os.path.dirname(__file__)
76-
with open(os.path.join(pwd, 'userlist')) as f:
77-
for line in f:
78-
if not line:
79-
continue
80-
parts = line.split()
81-
# in case of newline at the end of userlist file
82-
if len(parts) >= 1:
83-
name = parts[0]
84-
whitelist.add(name)
85-
if len(parts) > 1 and parts[1] == 'admin':
86-
admin.add(name)
60+
# Allowed admins
61+
admin = os.environ.get('JUPYTERHUB_ADMIN')
62+
if admin:
63+
c.Authenticator.admin_users = [admin]

0 commit comments

Comments
 (0)