[英]Docker-compose run command and keep the container running with ports
我正在嘗試運行運行 jupyter 筆記本的 Docker-compose 文件,並且我希望它每次運行時執行命令以將當前筆記本導出為 html (用於視覺參考)。 但是容器不會繼續運行。 我該如何解決?
我的 docker-compose 文件:
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""
我的 Dockerfile:
FROM python:3.7-slim-stretch
# Setup and installations
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
您正在使用jupyter nbconvert
命令覆蓋通常在容器中執行的命令。 由於這是一次性命令,因此您看到的行為是預期的。
一個簡單的解決方案是修改容器的CMD
以包含jupyter nbconvert
,如下所示:
FROM you_image
#
# YOUR DOCKERFILE LINES
#
CMD ["bash", "-c", "YOUR_CURRENT_CMD", "&&", "jupyter", "nbconvert", "Untitled.ipynb", "--template", "toc2", "--output", "Untitled_toc2.html"]
nbconvert 命令是一次性命令,只需為其主要目的設置容器即可運行 jupyter,並在需要時使用 nbconvert,因為容器不需要它來運行。
也許設置一個別名或 Makefile 以避免鍵入命令,否則您需要重新啟動容器以重新導出那些 html 文件,這根本不值得。
謝謝大家,感謝您的建議。
我發現最簡單的方法是在單獨的容器中運行命令並分配相同的圖像名稱,這樣它就不會再次構建:
version: "3"
services:
jupy_export:
image: note-im
build: .
volumes:
- irrelevant:/app/
command: jupyter nbconvert Untitled.ipynb --template toc2 --output "Untitled.html"
jupy:
image: note-im
build: .
volumes:
- irrelevant:/app/
ports:
- "8888:8888"
否則我可以在我的筆記本上運行這個命令:
!jupyter nbconvert Untitled.ipynb --template toc2 --output "Untitled.html"
這將允許我在不停止容器的情況下繼續工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.