Skip to content

Commit faf62d3

Browse files
committed
revisions to make restarting Jupyter lab in container easier
1 parent ac7e461 commit faf62d3

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

Docker/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,17 @@ RUN echo "Installing Miniforge..." \
8282
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete
8383

8484

85-
COPY --chown=${NB_USER}:${NB_USER} ./ECCO-v4-Python-Tutorial /home/${NB_USER}/ECCO-v4-Python-Tutorial
85+
COPY --chown=${NB_USER}:${NB_USER} ./ECCO-v4-Python-Tutorial ${HOME}/ECCO-v4-Python-Tutorial
8686

8787
RUN echo "Using environment.yml to create conda environment ${CONDA_ENV}" & \
8888
mamba env create --name ${CONDA_ENV} \
89-
-f ./ECCO-v4-Python-Tutorial/Docker/environment.yml
89+
-f ${HOME}/ECCO-v4-Python-Tutorial/Docker/environment.yml
90+
91+
# create symlink from home directory to jupyter_lab_start_docker.sh
92+
RUN ln -s ${HOME}/ECCO-v4-Python-Tutorial/Docker/jupyter_lab_start_docker.sh \
93+
${HOME}/jupyter_lab_start_docker.sh
9094

9195
EXPOSE 8888
9296

9397
# start jupyter lab inside the container
94-
ENTRYPOINT ["./ECCO-v4-Python-Tutorial/Docker/jupyter_lab_start_docker.sh"]
98+
ENTRYPOINT ["${HOME}/jupyter_lab_start_docker.sh"]

Docker/README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,32 @@ As Jupyter lab is launched, you will see a lot of output tagged `ServerApp` or `
2828

2929
## Open Jupyter lab in your browser
3030

31-
Now you need to open a connection between your local machine and the EC2 instance with the correct port forwarding. This will look something like
31+
Now you need to open a connection between your local machine and the EC2 instance with the correct port forwarding. On your local machine you can use any unused port; note that if you are already running Jupyter lab/notebooks locally that port 8888 will likely already be in use. This example uses 9889 as the local port
3232

3333
```bash
3434
ssh -i ~/.ssh/aws_ec2.pem -L 9889:localhost:8888 ec2-user@100.104.70.127
3535
```
3636

37-
and then in a browser window on your local machine, access the port you specified before `localhost` above
37+
and in a browser window on your local machine, access the port you specified before `localhost` above
3838

3939
```bash
4040
http://localhost:9889
4141
```
4242

43-
You will see a screen that asks for a password, but if you didn't enter any before, you can just go ahead and click `Login`. Now you have access to the tutorial repository, and the tutorials are in the directory `Tutorials_as_Jupyter_Notebooks`. Enjoy!
43+
You will see a screen that asks for a password, but if you didn't enter any before, you can just go ahead and click `Login`. Now you have access to the tutorial repository, and the tutorials are in the directory `Tutorials_as_Jupyter_Notebooks`.
44+
45+
## Re-connect to Jupyter lab in Docker container
46+
47+
If the Docker container is stopped or exited, the Jupyter lab session will also exit. To restart a Docker container use `docker ps -a` to find the container name and ID, and then use
48+
49+
```bash
50+
docker start <container-name or id>
51+
```
52+
53+
to re-start the container. Then you may need to run the following on your instance to re-start Jupyter lab within the container:
54+
55+
```bash
56+
docker exec -it <container-name or id> ~/jupyter_lab_start_docker.sh
57+
```
58+
59+
and you should see the `ServerApp` and `LabApp` output appear indicating that the session has started. Then you can use `Ctrl-p` `Ctrl-q` to escape that window from the container.

Docker/jupyter_lab_start_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ nocolor_start='\033[0m'
99

1010

1111
# Add Earthdata credentials to ~/.netrc if they are not already present
12-
sh ./ECCO-v4-Python-Tutorial/Docker/earthdata_auth_docker.sh
12+
sh ~/ECCO-v4-Python-Tutorial/Docker/earthdata_auth_docker.sh
1313

1414
echo "Starting Jupyter lab session!"
1515
echo ""
@@ -29,7 +29,7 @@ PW="$(python3 -c 'from jupyter_server.auth import passwd; import getpass; print(
2929
# Start Jupyter lab
3030
source /srv/conda/bin/activate
3131
conda activate jupyter
32-
jupyter lab --no-browser --autoreload --port=${user_port} --ip='0.0.0.0' --NotebookApp.token='' --NotebookApp.password=\"$PW\" --notebook-dir=\"./ECCO-v4-Python-Tutorial\"
32+
jupyter lab --no-browser --autoreload --port=${user_port} --ip='0.0.0.0' --NotebookApp.token='' --NotebookApp.password=\"$PW\" --notebook-dir=\"~/ECCO-v4-Python-Tutorial\"
3333

3434
# Print info about session
3535
echo -e "${red_start}Started Jupyter lab in Docker container"

0 commit comments

Comments
 (0)