首页 > 解决方案 > 如何配置 docker-compose 卷访问权限

问题描述

我正在尝试根据文档在我的 Synology NAS 上安装带有 docker 和我自己的 docker-compose.yml 文件的 gitlab

当我在我的 Synology(使用终端)上运行此文件时,出现退出代码 1 的错误:

Ran /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions 返回 1

如何配置我的目录或 docker-compose 文件来更正此错误?

我已经执行chmod -R 777chown -R root:root在数据和日志和配置上。

web:
   image: 'gitlab/gitlab-ce:latest'
   restart: always
   hostname: 'gitlab.example.com'
   environment:
     GITLAB_OMNIBUS_CONFIG: |
       external_url 'https://gitlab.example.com'
       # Add any other gitlab.rb configuration here, each on its own line
   ports:
     - '80:80'
     - '443:443'
     - '22:22'
   volumes:
     - '/srv/gitlab/config:/etc/gitlab'
     - '/srv/gitlab/logs:/var/log/gitlab'
     - '/srv/gitlab/data:/var/opt/gitlab

容器退出失败(返回 1),错误如下:

[2019-02-10T08:15:49+00:00] 信息:在重新引发异常之前运行排队的延迟通知 [2019-02-10T08:15:49+00:00] 错误:运行异常处理程序 [2019-02 -10T08:15:49+00:00] 错误:异常处理程序完成 [2019-02-10T08:15:49+00:00] 致命:Stacktrace 转储到 /opt/gitlab/embedded/cookbooks/cache/chef-stacktrace .out [2019-02-10T08:15:49+00:00] 致命:如果您提交错误报告,请提供 stacktrace.out 文件的内容 [2019-02-10T08:15:49+00:00]致命:Mixlib::ShellOut::ShellCommandFailed:execute[/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions](gitlab::gitlab-shell line 101)有一个错误:Mixlib: :ShellOut::ShellCommandFailed: 预期进程以 [0] 退出,但收到“1”---- 开始输出 /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions ---- STDOUT: STDERR: /opt/gitlab/embedded/service/gitlab-shell/lib /gitlab_logger.rb:30:in initialize': Permission denied @ rb_sysopen - /var/log/gitlab/gitlab-shell/gitlab-shell.log (Errno::EACCES) from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_logger.rb:30:in 从 /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_logger.rb:30:in 打开' initialize' from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_logger.rb:120:in 来自 /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_logger.rb:120:in <top (required)>' from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_keys.rb:4:in require_relative' 来自 /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_keys.rb:4:in <top (required)>' from /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys:24:in 需要'来自 /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys:24:in `' ---- 结束输出 /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions ---- Ran /opt/gitlab/embedded/service/gitlab-shell/bin/ gitlab-keys 检查权限返回 1

标签: dockerdocker-composegitlabsynology

解决方案


我已经复制了您的设置,并且 docker logs (web_container_id) 给出的最后一个输出是

=> /var/log/gitlab/gitlab-rails/sidekiq_exporter.log <==
[2019-02-11 17:16:20] 127.0.0.1 - - [11/Feb/2019:17:16:20 UTC] "GET /metrics HTTP/1.1" 200 1298 "-" "Prometheus/2.5.0"

您的问题与从执行 docker 的用户访问您的目录有关,因为它从文件夹和 /srv 文件夹继承权限,它是超级用户文件夹。

您为在 linux 上安装 docker 进行了后续配置?

https://docs.docker.com/install/linux/linux-postinstall/

除此之外,您需要确保执行 docker-compose 的用户可以访问您的主机目录,之后它也将不起作用。你说你在 chmod 777 之后使用了chown -R root:root ?如果您在没有 root 的情况下运行,它将不会产生任何影响。

Dockerfile:

version: "3"
services:
  web:
   image: gitlab/gitlab-ce:latest
   restart: always
   hostname: gitlab.example.com
   environment:
     GITLAB_OMNIBUS_CONFIG: |
       external_url 'https://gitlab.example.com'
   ports:
     - 80:80
     - 443:443
     - 22:22
   volumes:
     - /srv/gitlab/config:/etc/gitlab
     - /srv/gitlab/logs:/var/log/gitlab
     - /srv/gitlab/data:/var/opt/gitlab

推荐阅读