-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from janpfeifer/docker
Docker customization
- Loading branch information
Showing
6 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# This script is included in the Docker, and is executed at startup of the docker, allowing the user to write | ||
# an arbitrary setup script in `autostart.sh` for the image -- things like installing databases, credentials, etc. | ||
# | ||
# Notice ${NOTEBOOKS} is /notebooks in the container, and is assumed to be mounted from the host directory that | ||
# will have the users notebooks. | ||
|
||
# Makes sure we are not using $NB_USER's GOPATH. | ||
export GOPATH=/root/go | ||
|
||
# Check if autostart.sh exists | ||
if [[ -f "${NOTEBOOKS}/autostart.sh" ]]; then | ||
# Check if it's owned by root and is executable | ||
if [[ "$(stat -c '%U' "${NOTEBOOKS}/autostart.sh")" = "root" && -x "${NOTEBOOKS}/autostart.sh" ]]; then | ||
# Run autostart.sh as root | ||
echo "Running autostart.sh as root..." | ||
"${NOTEBOOKS}/autostart.sh" | ||
else | ||
# Print a message indicating why it's not running | ||
echo "autostart.sh exists but is not owned by root or not executable. Not running it." | ||
fi | ||
else | ||
echo "No autostart.sh initialization script." | ||
fi | ||
|
||
# Run JupyterLab from $NOTEBOOKS as user $NB_USER. | ||
su -l "${NB_USER}" -c "cd \"${NOTEBOOKS}\" ; jupyter lab" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Docker Customization | ||
|
||
1. The docker runs _JupyterLab_ and _GoNB_ under the user `$NB_USER` (== "jovyan"). | ||
2. It has configured `sudo` privileges for `apt update` and `apt install *`. So a cell with | ||
`!sudo apt install <my_package>` will work, and install your package. | ||
3. One can always create another docker based on `janpfeifer/gonb_jupyterlab@latest` | ||
4. Create an `autostart.sh` script, see next section. | ||
|
||
## Customization with `autostart.sh` | ||
|
||
If you create the file `autostart.sh` in the directory mounted under `/notebooks` in the container, | ||
**owned by `root` and with executable permissions**, it will be executed at start up of the container by default | ||
**as `root`**. | ||
|
||
This allows you to download/install databases, or set up credentials, etc. | ||
|
||
Example of an `autostart.sh` that: | ||
|
||
- Sets the timezone | ||
- Installs [`nats`](github.com/nats-io/natscli/) for the jupyer user (given by `$NB_USER`). | ||
|
||
``` | ||
# Set the German timezone (so time.Now() returns German time) | ||
apt-get install -y tzdata | ||
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime | ||
# some locale magic to make "date" answer with German format | ||
echo 'de_DE.UTF-8 UTF-8' >> /etc/locale.gen | ||
locale-gen | ||
echo 'LC_ALL="de_DE.utf8"' > /etc/default/locale | ||
export LC_ALL="de_DE.UTF-8" | ||
dpkg-reconfigure locales | ||
# check that it works | ||
date | ||
# Installing Go tools for $NB_USER. | ||
su -l "$NB_USER" -c "go install github.com/nats-io/natscli/nats@latest" | ||
``` | ||
|
||
More details in the `Dockerfile` and in the small start script `cmd/check_and_run_autostart.sh`. |