Skip to content

Commit ef98dd4

Browse files
committed
Make start.sh the entrypoint
Closes #1528
1 parent a4ede5d commit ef98dd4

File tree

19 files changed

+62
-46
lines changed

19 files changed

+62
-46
lines changed

docs/using/common.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,17 @@ docker run -it --rm \
225225

226226
### `start.sh`
227227

228-
The `start-notebook.py` script inherits most of its option handling capability from a more generic `start.sh` script.
229-
The `start.sh` script supports all the features described above but allows you to specify an arbitrary command to execute.
228+
Most of the configuration options in the `start-notebook.py` script are handled by an internal `start.sh` script that automatically runs before the command provided to the container
229+
(it's set as the container entrypoint).
230+
This allows you to specify an arbitrary command that takes advantage of all these features.
230231
For example, to run the text-based `ipython` console in a container, do the following:
231232

232233
```bash
233-
docker run -it --rm quay.io/jupyter/base-notebook start.sh ipython
234+
docker run -it --rm quay.io/jupyter/base-notebook ipython
234235
```
235236

236237
This script is handy when you derive a new Dockerfile from this image and install additional Jupyter applications with subcommands like `jupyter console`, `jupyter kernelgateway`, etc.
237238

238-
### Others
239-
240-
You can bypass the provided scripts and specify an arbitrary start command.
241-
If you do, keep in mind that features, supported by the `start.sh` script and its kin, will not function (e.g., `GRANT_SUDO`).
242-
243239
## Conda Environments
244240

245241
The default Python 3.x [Conda environment](https://conda.io/projects/conda/en/latest/user-guide/concepts/environments.html) resides in `/opt/conda`.

docs/using/selecting.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ It contains:
3434
- [mamba](https://github.com/mamba-org/mamba): "reimplementation of the conda package manager in C++". We use this package manager by default when installing packages.
3535
- Unprivileged user `jovyan` (`uid=1000`, configurable, [see options in the common features section](./common.md) of this documentation) in group `users` (`gid=100`)
3636
with ownership over the `/home/jovyan` and `/opt/conda` paths
37-
- `tini` as the container entry point
38-
- A `start.sh` script as the default command - useful for running alternative commands in the container as applications are added (e.g. `ipython`, `jupyter kernelgateway`, `jupyter lab`)
37+
- `tini` and a `start.sh` script as the container entry point - useful for running alternative commands in the container as applications are added (e.g. `ipython`, `jupyter kernelgateway`, `jupyter lab`)
3938
- A `run-hooks.sh` script, which can source/run files in a given directory
4039
- Options for a passwordless sudo
4140
- Common system libraries like `bzip2`, `ca-certificates`, `locales`

images/base-notebook/start-notebook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
os.execvp(command[0], command)
1515

1616

17-
# Wrap everything in start.sh, no matter what
18-
command = ["/usr/local/bin/start.sh"]
17+
# Entrypoint is start.sh
18+
command = []
1919

2020
# If we want to survive restarts, tell that to start.sh
2121
if os.environ.get("RESTARTABLE") == "yes":

images/base-notebook/start-singleuser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import shlex
66
import sys
77

8-
command = ["/usr/local/bin/start.sh", "jupyterhub-singleuser"]
8+
# Entrypoint is start.sh
9+
command = ["jupyterhub-singleuser"]
910

1011
# set default ip to 0.0.0.0
1112
if "--ip=" not in os.environ.get("NOTEBOOK_ARGS", ""):

images/docker-stacks-foundation/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ RUN set -x && \
124124
fix-permissions "/home/${NB_USER}"
125125

126126
# Configure container startup
127-
ENTRYPOINT ["tini", "-g", "--"]
128-
CMD ["start.sh"]
127+
ENTRYPOINT ["tini", "-g", "--", "start.sh"]
129128

130129
# Copy local files as late as possible to avoid cache busting
131130
COPY run-hooks.sh start.sh /usr/local/bin/

images/docker-stacks-foundation/start.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ else
3434
cmd=( "$@" )
3535
fi
3636

37+
# Backwards compatibility: start.sh is executed by default in ENTRYPOINT so
38+
# should no longer be specified in CMD
39+
if [ "${_START_SH_EXECUTED}" = "1" ]; then
40+
_log "WARNING: start.sh is the default ENTRYPOINT, do not include it in CMD"
41+
_log "Executing the command:" "${cmd[@]}"
42+
exec "${cmd[@]}"
43+
else
44+
export _START_SH_EXECUTED=1
45+
fi
46+
47+
3748
# NOTE: This hook will run as the user the container was started with!
3849
# shellcheck disable=SC1091
3950
source /usr/local/bin/run-hooks.sh /usr/local/bin/start-notebook.d

tests/all-spark-notebook/test_spark_notebooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_nbconvert(container: TrackedContainer, test_file: str) -> None:
3333
timeout=60,
3434
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
3535
tty=True,
36-
command=["start.sh", "bash", "-c", command],
36+
command=["bash", "-c", command],
3737
)
3838

3939
expected_file = f"{output_dir}/{test_file}.md"

tests/base-notebook/test_container_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_nb_user_change(container: TrackedContainer) -> None:
3535
tty=True,
3636
user="root",
3737
environment=[f"NB_USER={nb_user}", "CHOWN_HOME=yes"],
38-
command=["start.sh", "bash", "-c", "sleep infinity"],
38+
command=["bash", "-c", "sleep infinity"],
3939
)
4040

4141
# Give the chown time to complete.

tests/base-notebook/test_pandoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def test_pandoc(container: TrackedContainer) -> None:
1212
logs = container.run_and_wait(
1313
timeout=10,
1414
tty=True,
15-
command=["start.sh", "bash", "-c", 'echo "**BOLD**" | pandoc'],
15+
command=["bash", "-c", 'echo "**BOLD**" | pandoc'],
1616
)
1717
assert "<p><strong>BOLD</strong></p>" in logs

tests/base-notebook/test_start_container.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ def test_tini_entrypoint(
7676
https://superuser.com/questions/632979/if-i-know-the-pid-number-of-a-process-how-can-i-get-its-name
7777
"""
7878
LOGGER.info(f"Test that {command} is launched as PID {pid} ...")
79-
running_container = container.run_detached(
80-
tty=True,
81-
command=["start.sh"],
82-
)
79+
running_container = container.run_detached(tty=True)
8380
# Select the PID 1 and get the corresponding command
8481
cmd = running_container.exec_run(f"ps -p {pid} -o comm=")
8582
output = cmd.output.decode("utf-8").strip("\n")

0 commit comments

Comments
 (0)