I am trying to run Docker-compose file that runs jupyter notebooks, and I want it to execute a command to export the current notebooks as html (for visual reference) every time I run it. But the container doesn’t continue running. How do I fix that?
My docker-compose file:
version: "3"
services:
jupy:
build: .
volumes:
- irrelevant:/app/
ports:
- "8888:8888"
#This command executes and exists
#I want it to run and then I continue working
command: bash -c "jupyter nbconvert Untitled.ipynb --template toc2 --output "Untitled_toc2.html""
My Dockerfile:
FROM python:3.7-slim-stretch
# Setup and installations
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
3
Answers
Thank you all, your advice is appreciated.
The easiest ways I found is to run the command in a separate container and assign the same image name so it doesn't build again:
Otherwise I could run this command on my notebooks as:
Which would allow me to keep working without stopping the container.
You are overriding the command that would normally be executed in your container with the
jupyter nbconvert
command. Since this is a one-off command the behaviour you see is expected.A simple solution would be to modify the
CMD
of your container to include thejupyter nbconvert
, something like this:The nbconvert command is a one-off command, just set up the container for it’s main purpose, to run jupyter, and use the nbconvert when you need it, as it’s not needed for the container to run.
Maybe set up an alias or a Makefile to avoid typing the command, in other way you need to restart the container to re-export those html files, which is not worth it at all.