Skip to content

Commit ccd512c

Browse files
committed
Edit prerequisites and OAuth
1 parent d99aa82 commit ccd512c

File tree

2 files changed

+107
-72
lines changed

2 files changed

+107
-72
lines changed

README.md

Lines changed: 107 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
# jupyterhub-deploy-docker
1111

12-
The **jupyterhub-deploy-docker** repository provides a reference
12+
**jupyterhub-deploy-docker** provides a reference
1313
deployment of [JupyterHub](https://github.com/jupyter/jupyterhub), a
1414
multi-user [Jupyter Notebook](http://jupyter.org/) environment, on a
1515
**single host** using [Docker](https://docs.docker.com).
1616

17-
Possible **use cases** for this deployment may include, but are not
18-
limited to:
17+
Possible **use cases** include, but are not limited to:
1918

20-
* A JupyterHub demo environment that you can spin up relatively quickly.
21-
* A multi-user Jupyter Notebook environment for small classes, teams,
22-
or departments.
19+
* Creating a JupyterHub demo environment that you can spin up relatively
20+
quickly.
21+
* Providing a multi-user Jupyter Notebook environment for small classes,
22+
teams, or departments.
2323

2424
**Disclaimer:** This deployment is **NOT** intended for a production
2525
environment.
@@ -51,82 +51,115 @@ Key components of this reference deployment are:
5151

5252
## Prerequisites
5353

54-
* **Docker**: This deployment uses Docker for all the things, via
55-
[Docker Compose](https://docs.docker.com/compose/overview/). It
56-
requires [Docker Engine](https://docs.docker.com/engine) 1.12.0 or
57-
higher. Use the [Docker installation instructions](https://docs.docker.com/engine/installation/)
58-
for your environment.
59-
60-
* **HTTPS and SSL**: This deployment configures JupyterHub to use HTTPS
61-
connections (the default). You must provide TLS certificate chain and
62-
key files in the JupyterHub configuration. If you do not have an
63-
existing certificate chain and key, you can [create self-signed versions](https://jupyter-notebook.readthedocs.org/en/latest/public_server.html#using-ssl-for-encrypted-communication),
64-
or obtain real ones from [Let's Encrypt](https://letsencrypt.org)
65-
(see the [letsencrypt example](examples/letsencrypt/README.md) for
66-
instructions).
54+
### Docker
55+
56+
This deployment uses Docker for all the things, via [Docker Compose](https://docs.docker.com/compose/overview/).
57+
[Docker Engine](https://docs.docker.com/engine) 1.12.0 or higher is
58+
required. Use [Docker's installation instructions](https://docs.docker.com/engine/installation/)
59+
to set up Docker for your environment.
6760

68-
To verify that you are set up with docker, via a local installation or
69-
[docker-machine](./docs/docker-machine.md), run:
61+
To verify your docker installation, whether running docker as a local installation or using [docker-machine](./docs/docker-machine.md),
62+
enter these commands:
7063

7164
```bash
65+
docker version
7266
docker ps
7367
```
7468

75-
This command will return running Docker processes.
69+
70+
71+
### HTTPS and SSL/TLS certificate
72+
73+
This deployment configures JupyterHub to use HTTPS connections (the
74+
default). You must provide TLS certificate chain and key file in the
75+
JupyterHub configuration.
76+
77+
1. Obtain the domain name that you wish to use for JupyterHub, for
78+
example, `myfavoritesite.com` or `jupiterplanet.org`.
79+
80+
1. If you do not have an existing certificate chain and key, you can
81+
[create self-signed versions](https://jupyter-notebook.readthedocs.org/en/latest/public_server.html#using-ssl-for-encrypted-communication),
82+
or obtain real ones from [Let's Encrypt](https://letsencrypt.org)
83+
(see the [letsencrypt example](examples/letsencrypt/README.md) for
84+
instructions).
85+
86+
1. Copy the certificate chain and key files for the JupyterHub server
87+
to a directory named `secrets` within this repository directory.
88+
These will be added to the JupyterHub Docker image at build time. For
89+
example, create a `secrets` directory in the root of this repo and
90+
copy the certificate and key files (`jupyterhub.crt` and `jupyterhub.key`)
91+
to this directory:
92+
93+
```bash
94+
mkdir -p secrets
95+
cp jupyterhub.crt jupyterhub.key secrets/
96+
```
7697

7798

7899
## Authenticator setup
79100

80101
This deployment uses GitHub OAuth to authenticate users.
81-
It requires that you create a [GitHub application](https://github.com/settings/applications/new).
82-
You will need to specify an OAuth callback URL in the following form:
102+
103+
It requires that you create and register a [GitHub OAuth application](https://github.com/settings/applications/new)
104+
by filling out a form on the GitHub site:
105+
106+
![GitHub OAuth application form](docs/oauth-form.png)
107+
108+
In this form, you will specify the OAuth application's callback URL in
109+
this format:
83110

84111
```
85112
https://<myhost.mydomain>/hub/oauth_callback
86113
```
87114

88-
You must pass the secrets that GitHub provides for your application to JupyterHub at runtime.
89-
You can do this by setting the `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`,
90-
and `OAUTH_CALLBACK_URL` environment variables when you run the JupyterHub container,
91-
or you can add them to the `.env` file in the root directory of this repository. For example,
115+
After submitting the GitHub form, your registered GitHub OAuth
116+
application is assigned a unique Client ID and Client Secret. The
117+
Client Secret should be kept private.
92118

93-
```
94-
GITHUB_CLIENT_ID=<github_client_id>
95-
GITHUB_CLIENT_SECRET=<github_client_secret>
96-
OAUTH_CALLBACK_URL=https://<myhost.mydomain>/hub/oauth_callback
97-
```
119+
You must pass the GitHub OAuth Client ID, Client Secret and OAuth
120+
callback url to JupyterHub at runtime. You can do this by either:
98121

99-
**Note:** The `.env` file is a special file that Docker Compose uses to lookup environment variables.
100-
If you choose to place the GitHub secrets in this file,
101-
you should ensure that this file remains private
102-
(e.g., do not commit the secrets to source control).
122+
- setting the `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, and
123+
`OAUTH_CALLBACK_URL` environment variables when you run the
124+
JupyterHub container, or
125+
- add them to the `.env` file in the root directory of this repository.
126+
For example, update the following lines in the `.env` file:
103127

128+
**.env**
129+
```
130+
GITHUB_CLIENT_ID=<github_client_id>
131+
GITHUB_CLIENT_SECRET=<github_client_secret>
132+
OAUTH_CALLBACK_URL=https://<myhost.mydomain>/hub/oauth_callback
133+
```
134+
135+
**Note:** The `.env` file is a special file that Docker Compose uses
136+
to lookup environment variables. If you choose to place the GitHub
137+
OAuth application settings in this file, you should make sure that the
138+
file remains private (be careful to not commit the `.env` file with
139+
these secrets to source control).
104140

105-
## Build the JupyterHub Docker image
106141

107-
Configure JupyterHub and build it into a Docker image.
142+
## Build the JupyterHub Docker image
108143

109-
1. Copy the TLS certificate chain and key files for the JupyterHub server to a directory named `secrets` within this repository directory. These will be added to the JupyterHub Docker image at build time. If you do not have a certificate chain and key, you can either [create self-signed versions](https://jupyter-notebook.readthedocs.org/en/latest/public_server.html#using-ssl-for-encrypted-communication), or obtain real ones from [Let's Encrypt](https://letsencrypt.org) (see the [letsencrypt example](examples/letsencrypt/README.md) for instructions).
144+
Configure JupyterHub
110145

111-
```
112-
mkdir -p secrets
113-
cp jupyterhub.crt jupyterhub.key secrets/
114-
```
146+
and build it into a Docker image.
115147

116148
1. Create a `userlist` file with a list of authorized users. At a minimum, this file should contain a single admin user. The username should be a GitHub username. For example:
117149

118-
```
150+
**file**
151+
```
119152
jtyberg admin
120-
```
153+
```
121154

122155
The admin user will have the ability to add more users in the JupyterHub admin console.
123156

124157
1. Use [docker-compose](https://docs.docker.com/compose/reference/) to build the
125158
JupyterHub Docker image on the active Docker machine host:
126159

127-
```
160+
```bash
128161
make build
129-
```
162+
```
130163

131164

132165
## Spawner: Prepare the Jupyter Notebook Image
@@ -159,7 +192,7 @@ Notebook server that is compatible with JupyterHub).
159192

160193
You can pull the image using the following command:
161194

162-
```
195+
```bash
163196
make notebook_image
164197
```
165198

@@ -170,19 +203,20 @@ Run the JupyterHub container on the host.
170203

171204
To run the JupyterHub container in detached mode:
172205

173-
```
206+
```bash
174207
docker-compose up -d
175208
```
176209

177210
Once the container is running, you should be able to access the JupyterHub console at
178211

212+
**file**
179213
```
180214
https://myhost.mydomain
181215
```
182216

183217
To bring down the JupyterHub container:
184218

185-
```
219+
```bash
186220
docker-compose down
187221
```
188222

@@ -192,6 +226,14 @@ docker-compose down
192226

193227
`make build` does a few things behind the scenes, to set up the environment for JupyterHub:
194228

229+
### Create a JupyterHub Data Volume
230+
231+
Create a Docker volume to persist JupyterHub data. This volume will reside on the host machine. Using a volume allows user lists, cookies, etc., to persist across JupyterHub container restarts.
232+
233+
```bash
234+
docker volume create --name jupyterhub-data
235+
```
236+
195237
### Create a Docker Network
196238

197239
Create a Docker network for inter-container communication. The benefits of using a Docker network are:
@@ -201,18 +243,10 @@ Create a Docker network for inter-container communication. The benefits of usin
201243

202244
Here we create a Docker network named `jupyterhub-network`. Later, we will configure the JupyterHub and single-user Jupyter Notebook containers to run attached to this network.
203245

204-
```
246+
```bash
205247
docker network create jupyterhub-network
206248
```
207249

208-
### Create a JupyterHub Data Volume
209-
210-
Create a Docker volume to persist JupyterHub data. This volume will reside on the host machine. Using a volume allows user lists, cookies, etc., to persist across JupyterHub container restarts.
211-
212-
```
213-
docker volume create --name jupyterhub-data
214-
```
215-
216250
---
217251

218252
## FAQ
@@ -221,7 +255,7 @@ docker volume create --name jupyterhub-data
221255

222256
Use `docker logs <container>`. For example, to view the logs of the `jupyterhub` container
223257

224-
```
258+
```bash
225259
docker logs jupyterhub
226260
```
227261

@@ -235,14 +269,15 @@ JupyterHub reads the Notebook image name from `jupyterhub_config.py`, which
235269
reads the Notebook image name from the `DOCKER_NOTEBOOK_IMAGE` environment
236270
variable:
237271

238-
```
272+
```python
239273
# DockerSpawner setting in jupyterhub_config.py
240274
c.DockerSpawner.container_image = os.environ['DOCKER_NOTEBOOK_IMAGE']
241275
```
242276

243277
By default, the`DOCKER_NOTEBOOK_IMAGE` environment variable is set in the
244278
`.env` file.
245279

280+
**file**
246281
```
247282
# Setting in the .env file
248283
DOCKER_NOTEBOOK_IMAGE=jupyter/scipy-notebook:2d878db5cbff
@@ -254,7 +289,7 @@ by setting the `DOCKER_NOTEBOOK_IMAGE` variable to a different Notebook
254289
image in the environment where you launch JupyterHub. For example, the
255290
following setting would be used to spawn single-user `pyspark` notebook servers:
256291

257-
```
292+
```bash
258293
export DOCKER_NOTEBOOK_IMAGE=jupyterhub/pyspark-notebook:2d878db5cbff
259294

260295
docker-compose up -d
@@ -282,25 +317,25 @@ There are multiple ways to [backup and restore](https://docs.docker.com/engine/u
282317

283318
Suppose you have the following running containers:
284319

285-
```
286-
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Names}}"
320+
```bash
321+
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Names}}"
287322

288-
CONTAINER ID IMAGE NAMES
289-
bc02dd6bb91b jupyter/minimal-notebook jupyter-jtyberg
290-
7b48a0b33389 jupyterhub jupyterhub
323+
CONTAINER ID IMAGE NAMES
324+
bc02dd6bb91b jupyter/minimal-notebook jupyter-jtyberg
325+
7b48a0b33389 jupyterhub jupyterhub
291326
```
292327

293328
In this deployment, the user's notebook directories (`/home/jovyan/work`) are backed by Docker volumes.
294329

295-
```
296-
docker inspect -f '{{ .Mounts }}' jupyter-jtyberg
330+
```bash
331+
docker inspect -f '{{ .Mounts }}' jupyter-jtyberg
297332

298-
[{jtyberg /var/lib/docker/volumes/jtyberg/_data /home/jovyan/work local rw true rprivate}]
333+
[{jtyberg /var/lib/docker/volumes/jtyberg/_data /home/jovyan/work local rw true rprivate}]
299334
```
300335

301336
We can backup the user's notebook directory by running a separate container that mounts the user's volume and creates a tarball of the directory.
302337

303-
```
338+
```bash
304339
docker run --rm \
305340
-u root \
306341
-v /tmp:/backups \

docs/oauth-form.png

244 KB
Loading

0 commit comments

Comments
 (0)