[英]Why does using a blank/empty volume in docker-compose.yml allow persistence but using a relative path fails (eg jenkins gui unavailable)?
./jenkins_home:...
) prevent jenkins from serving it's GUI yet an empty volume path allows jenkins to serve it's GUI?为什么相对主机卷路径(即./jenkins_home:...
)阻止 jenkins 为其 GUI 提供服务,而空卷路径允许 jenkins 为其提供 GUI?volumes: jenkins_home: <no value>
) stored on the host?主机上存储的别名主机卷(即volumes: jenkins_home: <no value>
)在哪里?This situation is similar to https://stackoverflow.com/a/57040274/7490713 but I'm unsure why the solution works.这种情况类似于https://stackoverflow.com/a/57040274/7490713但我不确定该解决方案为何有效。
Using Docker Desktop docker-compose
on Windows 10, with a relative path (ie, ./jenkins_home:...
) for the host volume location correctly persists data to the current directory, & port 50000 is accessible, however, port 8080 (ie, Jenkins GUI) is unavailable:在 Windows 10 上使用 Docker 桌面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.
Whereas using an empty host volume path works:而使用空主机卷路径有效:
# ...
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
时可以访问 jenkins GUI,主机卷路径别名如下(虽然我不确定它在主机上的位置):通过docker run
成功运行使 jenkins GUI 可用:
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?相对卷路径使 jenkins GUI 无法访问,这似乎是因为在这种情况下持久性不起作用,这会阻止 jenkins 在http://localhost:8080
上提供它的 GUI,并且以某种方式通过卷别名使用空卷路径允许持久性和提供 GUI - 问题是为什么相对路径导致 GUI 不提供服务而空路径导致 GUI 提供服务?
Since the GUI not being available is an application-specific issue this can not be answered solely from a docker
perspective.由于 GUI 不可用是一个特定于应用程序的问题,因此不能docker
的角度来回答。 But most probably the cause here is the difference between volumes
and bind-mounts
in docker
, namely in the way these are initialized on creation:但最有可能的原因是docker
中的volumes
和bind-mounts
之间的差异,即它们在创建时的初始化方式:
While for bind-mounts
simply the specified directory on the host will be mounted into the container as-is, new volumes
are created by docker
if they don't exist yet and populated with the contents of the target directory from the image .对于bind-mounts
,主机上的指定目录将按原样挂载到容器中,如果新volumes
尚不存在,则由docker
创建,并填充镜像中目标目录的内容。 This includes also setting the same permissions for the volume
.这还包括为volume
设置相同的权限。
So for your question 1.: look for error messages in the container's log regarding permission denied
/ access denied
or missing files/directories in /var/jenkins_home
.因此,对于您的问题 1:在容器的日志中查找有关/var/jenkins_home
中的permission denied
/ access denied
或文件/目录丢失的错误消息。 If so you just need to set the correct permissions for ./jenkins_home
or initialize the expected contents manually (how exactly is an application-specific issue).如果是这样,您只需要为./jenkins_home
设置正确的权限或手动初始化预期的内容(特定于应用程序的问题到底是什么)。
Regarding question 2.: where the contents of the volumes are stored on disk is managed by docker
and dependent on the configuration of the docker
daemon and host.关于问题 2:卷的内容存储在磁盘上的位置由docker
管理,并取决于docker
守护程序和主机的配置。 Normally you should not need to care about this and only manage them via thedocker volume
command .通常你不需要关心这个并且只通过docker volume
命令管理它们。
See the docker
documentation for more on this.有关更多信息,请参阅docker
文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.