問題:
- 為什么相對主機卷路徑(即
./jenkins_home:...)阻止 jenkins 為其 GUI 提供服務,而空卷路徑允許 jenkins 為其提供 GUI 服務? - 別名主機卷(即
volumes: jenkins_home: <no value>)存盤在主機上的什么位置?
語境:
這種情況類似于https://stackoverflow.com/a/57040274/7490713但我不確定為什么該解決方案有效。
在 Windows 10 上使用 Docker Desktop ,主機卷位置docker-compose的相對路徑(即./jenkins_home:...)正確地將資料保存到當前目錄,并且埠 50000 可以訪問,但是埠 8080(即 Jenkins GUI)不可用:
version: '3.9'
services:
jenkins:
image: 'jenkins/jenkins:lts'
restart: 'unless-stopped'
ports:
- '8080:8080'
- '50000:50000'
volumes:
- './jenkins_home:/var/jenkins_home' # Relative path (jenkins GUI doesn't work).
volumes:
jenkins_home:
ping http://localhost:50000 # Success.
ping http://localhost:8080 # Not found.
而使用空主機卷路徑有效:
# ...
services:
jenkins:
# ...
volumes:
- 'jenkins_home:/var/jenkins_home' # Aliased empty path (jenkins GUI works).
volumes:
# NOTE: Empty path value used below.
jenkins_home:
ping http://localhost:8080 # Success.
For comparison, the jenkins GUI is accessible when using docker run with a host volume path alias as below (although I'm unsure where this is located on the host machine):
Running jenkins via docker run successfully makes the jenkins GUI available:
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
The relative volume path makes the jenkins GUI inaccessible, it seems this is because persistence doesn't work in this situation, which prevents jenkins from serving it's GUI on http://localhost:8080, & somehow using an empty volume path via volume alias allows persistence & the GUI to be served - the question is why does the relative path cause the GUI to not serve yet the empty path causes the GUI to serve?
uj5u.com熱心網友回復:
由于 GUI 不可用是一個特定于應用程式的問題,因此不能僅從一個docker角度來回答。volumes但最有可能的原因是和bind-mountsin之間的差異docker,即它們在創建時初始化的方式:
雖然bind-mounts只是將主機上的指定目錄按原樣安裝到容器中,但如果它們尚不存在,volumes則會創建新目錄,并使用 image 中目標目錄的內容填充。這還包括為.dockervolume
因此,對于您的問題 1.:在容器日志中查找有關permission denied/access denied或/var/jenkins_home. 如果是這樣,您只需要./jenkins_home手動設定正確的權限或初始化預期的內容(究竟是應用程式特定的問題)。
關于問題 2:卷的內容存盤在磁盤dockerdocker上的位置由守護程式和主機的配置管理并取決于它。通常你不需要關心這個,只需要通過docker volume命令來管理它們。
有關更多資訊,docker請參閱檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/442168.html
標籤:docker jenkins docker-compose yaml docker-run
