简体   繁体   English

为什么在 docker-compose.yml 中使用空白/空卷允许持久性但使用相对路径失败(例如 jenkins gui 不可用)?

[英]Why does using a blank/empty volume in docker-compose.yml allow persistence but using a relative path fails (eg jenkins gui unavailable)?

Questions:问题:

  1. Why does a relative host volume path (ie, ./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?
  2. Where is the aliased host volume (ie, volumes: jenkins_home: <no value> ) stored on the host?主机上存储的别名主机卷(即volumes: jenkins_home: <no value> )在哪里?

Context:语境:

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中的volumesbind-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.

相关问题 如何使用docker-compose.yml文件命名卷? - How to name a volume using a docker-compose.yml file? 为什么 docker-compose 在随机路径中创建卷而不是我在 docker-compose.yml 中指定的路径? - Why is docker-compose creating volume in random path instead of the path I specified in docker-compose.yml? 如何在 docker-compose.yml 中为命名卷设置主机路径 - How to set a path on host for a named volume in docker-compose.yml `docker-compose.yml` 中的根级空 object 是什么意思? - What does a root level empty object for volume means in `docker-compose.yml`? 相对路径不适用于 docker-compose.yml 中的命名卷 - Relative path not working with named volumes in the docker-compose.yml 为什么在docker-compose.yml中使用多个env_files时变量替换不起作用? - Why does variables substitution not work when using multiple env_files in docker-compose.yml? 如何使用 docker-compose.yml 中的值将文件添加到 Docker 映像中的卷? - How can I add a file to a volume in a Docker image, using values from the docker-compose.yml? 如何使用 docker-compose.yml 在映射为卷的目录中克隆 GitHub 存储库? - How to clone a GitHub repo inside a directory mapped as a volume using docker-compose.yml? 如何使用docker-compose.yml和ecs-cli将EBS卷附加到我的容器 - how to attach a EBS volume to my container using docker-compose.yml and ecs-cli 如何在 Docker 中检查卷是否存在且不为空,并根据此运行不同的 docker-compose.yml? - How to check in Docker whether a volume exists and is not empty and run different docker-compose.yml depending on this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM