Docker

docker 命令無法從 makefile 中找到文件,但能夠直接從 CLI 中找到它

  • September 10, 2021

在終端中,一旦進入文件所在的目錄test.tex,我可以執行以下docker命令:

$ docker run -i --rm --name latex -v "WD":/usr/src/app -w /usr/src/app registry.gitlab.com/islandoftex/images/texlive:latest-with-cache pdflatex test

但是,如果我創建一個makefile包含以下內容的文件:

run-docker:
   docker run -i --rm --name latex -v "$PWD":/usr/src/app -w /usr/src/app registry.gitlab.com/islandoftex/images/texlive:latest-with-cache pdflatex test

在終端中執行以下命令:

$ make run-docker

導致以下錯誤:

docker run -i --rm --name latex -v "WD":/usr/src/app -w /usr/src/app registry.gitlab.com/islandoftex/images/texlive:latest-with-cache pdflatex test
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
! I can't find file `test'.
<*> test
       
(Press Enter to retry, or Control-D to exit)
Please type another input file name: 
! Emergency stop.
<*> test
       
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
make: *** [makefile:15 : run-docker] Erreur 1

如何解決這個問題(我猜這與 無關LaTeX)?

變數引用是錯誤的,你應該$(CURDIR)在 Makefile 中使用:

run-docker:
   docker run -i --rm --name latex -v "$(CURDIR)":/usr/src/app -w /usr/src/app registry.gitlab.com/islandoftex/images/texlive:latest-with-cache pdflatex test

引用自:https://unix.stackexchange.com/questions/668443