gpt4 book ai didi

docker - 在Windows主机上使用Docker设置Gitlab,共享文件夹出现问题

转载 作者:行者123 更新时间:2023-12-02 18:30:52 27 4
gpt4 key购买 nike

TLDR;

有谁知道如何解决“无法断言“/ var / opt / gitlab / git-data”的所有权是git”错误?

背景:

我想在运行Docker工具箱,版本17.04.0-ce,内部版本4845c56的WindowsServer2012R2上设置Gitlab Docker

问题/问题

我无法使共享文件夹在服务器的D盘上正常工作。我读到需要将文件夹添加到VirtualBox VM,这是通过VB GUI中的settings / shared folder菜单完成的。我将名称“gitlab”设置为路径“D:\ data \ gitlab”,然后选中自动挂载,使其永久,并将其设置为完全访问权限。

VM Shared Folder Settings

我启动了docker机器并运行了“docker-machine ssh $ machine-name”。我注意到这里没有/ media目录,因此我在主目录(/ home / docker / gitlab)中添加了一个文件夹,然后使用在多个论坛中找到的以下命令安装了共享文件夹:

sudo mount -t vboxsf gitlab /home/docker/gitlab

此时,我可以将文件添加到Windows主机目录或Docker VM中,并且看起来工作正常,并且显示测试文件。

现在,当我启动Gitlab Docker镜像时,我使用从其文档中修改的以下命令:
docker run --detach --hostname gitlab.example.com --publish 80:80 --name gitlab --volume /home/docker/gitlab:/etc/gitlab:Z --volume /home/docker/gitlab/logs:/var/log/gitlab:Z --volume /home/docker/gitlab/data:/var/opt/gitlab:Z gitlab/gitlab-ce

现在,我知道它似乎正在写入共享驱动器,因为所有这些文件都已生成,但是几秒钟后它崩溃了,并且我收到以下错误日志。

Files Generated when Running Gitlab Docker

错误日志:
Thank you for using GitLab Docker Image!
Current version: gitlab-ce=9.3.6-ce.0

Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:

docker exec -it gitlab vim /etc/gitlab/gitlab.rb
docker restart gitlab

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

If this container fails to start due to permission problems try to fix it by executing:

docker exec -it gitlab update-permissions
docker restart gitlab

Installing gitlab.rb config...
Generating ssh_host_rsa_key...
Generating public/private rsa key pair.
Your identification has been saved in /etc/gitlab/ssh_host_rsa_key.
Your public key has been saved in /etc/gitlab/ssh_host_rsa_key.pub.
The key fingerprint is:
SHA256:GyFlf9tl7ZuEbuE+dwZUYiyahdsRzpC1T7kwyUvoD+o root@gitlab.example.com
The key's randomart image is:
+---[RSA 2048]----+
| o .+oo |
| o .o*+o+.o|
| . . o*@+oo+|
| . o+o.Oo= |
| S o o++..|
| + oo + o|
| o .+ + |
| . o. .o|
| E .o..|
+----[SHA256]-----+
Generating ssh_host_ecdsa_key...
Generating public/private ecdsa key pair.
Your identification has been saved in /etc/gitlab/ssh_host_ecdsa_key.
Your public key has been saved in /etc/gitlab/ssh_host_ecdsa_key.pub.
The key fingerprint is:
SHA256:Kb99jG8EtMuTSdIuqBT3GLeD1D0wwTEcQhKgVJUlBjs root@gitlab.example.com
The key's randomart image is:
+---[ECDSA 256]---+
| .o+=*=+=+ |
|.. oo..=.. |
|. E . * . |
| o + +.B |
| +.BS* * |
| . +o= B . |
| . . .o = |
| . o. + |
| . .+. |
+----[SHA256]-----+
Generating ssh_host_ed25519_key...
Generating public/private ed25519 key pair.
Your identification has been saved in /etc/gitlab/ssh_host_ed25519_key.
Your public key has been saved in /etc/gitlab/ssh_host_ed25519_key.pub.
The key fingerprint is:
SHA256:lVxpu0UoyNPWVY6D9c+m/bUTyvKP6vuR4cTOYwQ0j+U root@gitlab.example.com
The key's randomart image is:
+--[ED25519 256]--+
| . o +.=o..|
| +.=o@o.+ |
| o+=.Eo o|
| . + .o.|
| S B +|
| B o= |
| .Oo +|
| ..o+.+|
| .+*+.oo|
+----[SHA256]-----+
Preparing services...
Starting services...
Configuring GitLab package...
/opt/gitlab/embedded/bin/runsvdir-start: line 24: ulimit: pending signals: cannot modify limit: Operation not permitted
/opt/gitlab/embedded/bin/runsvdir-start: line 34: ulimit: max user processes: cannot modify limit: Operation not permitted
/opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system
Configuring GitLab...

================================================================================
Error executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Failed asserting that ownership of "/var/opt/gitlab/git-data" was git
---- Begin output of set -x && [ "$(stat --printf='%U' $(readlink -f /var/opt/gitlab/git-data))" = 'git' ] ----
STDOUT:
STDERR: + readlink -f /var/opt/gitlab/git-data
+ stat --printf=%U /var/opt/gitlab/git-data
+ [ UNKNOWN = git ]
---- End output of set -x && [ "$(stat --printf='%U' $(readlink -f /var/opt/gitlab/git-data))" = 'git' ] ----
Ran set -x && [ "$(stat --printf='%U' $(readlink -f /var/opt/gitlab/git-data))" = 'git' ] returned 1

Cookbook Trace:
---------------
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/libraries/storage_directory_helper.rb:124:in `validate_command'
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/libraries/storage_directory_helper.rb:112:in `block in validate'
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/libraries/storage_directory_helper.rb:111:in `each_index'
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/libraries/storage_directory_helper.rb:111:in `validate'
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/libraries/storage_directory_helper.rb:87:in `validate!'
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/definitions/storage_directory.rb:35:in `block (3 levels) in from_file'

Resource Declaration:
---------------------
# In /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/definitions/storage_directory.rb

26: ruby_block "directory resource: #{params[:path]}" do
27: block do
28: # Ensure the directory exists
29: storage_helper.ensure_directory_exists(params[:path])
30:
31: # Ensure the permissions are set
32: storage_helper.ensure_permissions_set(params[:path])
33:
34: # Error out if we have not achieved the target permissions
35: storage_helper.validate!(params[:path])
36: end
37: not_if { storage_helper.validate(params[:path]) }
38: end
39: end

Compiled Resource:
------------------
# Declared in /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/definitions/storage_directory.rb:26:in `block in from_file'

ruby_block("directory resource: /var/opt/gitlab/git-data") do
params {:path=>"/var/opt/gitlab/git-data", :owner=>"git", :group=>nil, :mode=>"0700", :name=>"/var/opt/gitlab/git-data"}
action [:run]
retries 0
retry_delay 2
default_guard_interpreter :default
block_name "directory resource: /var/opt/gitlab/git-data"
declared_type :ruby_block
cookbook_name "gitlab"
recipe_name "gitlab-shell"
block #<Proc:0x000000054a99a8@/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/definitions/storage_directory.rb:27>
not_if { #code block }
end

Platform:
---------
x86_64-linux

有谁知道如何解决“无法断言“/ var / opt / gitlab / git-data”的所有权是git”错误?我对Docker /设置Gitlab还是有些陌生,所以很可能我会忽略了一些简单的事情。我已经花了几个小时在Google上进行搜索,而且似乎其他人在使用Docker Toolbox从Windows上获取共享文件夹以工作时也遇到了很多问题,因此希望这也会对其他人有所帮助。

最佳答案

背景

对于那些没有本地docker的人来说,一种解决方案(也许不是最好的)是使用vdi驱动器和共享文件夹。 vdi驱动器可以驻留在我们想要的驱动器上(如果您不想使用C驱动器,这很重要),并且用于允许Gitlab docker 对所需的任何东西进行整理,因此这就是我们要存储的位置持久卷。缺点是vdi不像简单的共享文件夹那样透明,因此对于备份,共享文件夹会使事情变得更容易/透明。

免责声明

我不是这方面的专家,因此请谨慎使用我所说的盐。

执行的步骤

在您想要的任何驱动器上创建一个新的vdi驱动器和共享文件夹

  • 关闭要用于gitlab的docker机器
  • 在virtualbox中,进入docker-machine上的设置,然后进入 Storage ,然后单击添加硬盘图标,然后创建新磁盘
  • 选择 VDI(VirtualBox磁盘镜像),然后单击。下一步
  • 选择动态分配的,然后单击。下一步
  • 通过单击带有绿色胡萝卜符号的文件夹来选择要存储vdi的名称和位置,然后选择vdi可以增长到的最大大小,然后单击创建
  • 现在在设置菜单中,切换到共享文件夹,然后单击添加新的共享文件夹图标
  • 在需要的位置创建一个 gitlabbackups 文件夹,然后选择自动挂载创建永久

  • 现在对驱动器进行分区和格式化
  • 启动/进入docker计算机(使用VBox窗口或cmd提示符下的docker-machine ssh <your docker machine name>)
  • 运行fdisk -l列出可用的驱动器,如果只安装了一个额外的vdi驱动器,则应该看到类似/ dev / sdb
  • 的内容。
  • 下一步是不可逆的,因此请自行决定执行此操作:输入命令fdisk /dev/sdb,然后输入n来创建新分区,p来创建主分区,并1
  • 现在格式化新分区(您可能还需要sudo):mkfs.ext4 /dev/sdb1

  • 在第二个vdi上使用持久卷运行docker,并在共享文件夹中备份

    样本Dockerfile:
    FROM gitlab/gitlab-ce:latest

    RUN apt-get update
    RUN apt-get install -y cron

    # Add a cron job to backup everyday
    RUN echo "0 5 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create STRATEGY=copy CRON=1" | crontab -
    # For an unknown reason, the cron job won't actually run unless cron is restarted
    CMD service cron restart && \
    /assets/wrapper

    样本docker-compose.yml:
    version: "3.0"
    services:
    gitlab:
    build: .
    restart: always
    ports:
    - "80:80"
    volumes:
    # These volumes are on the vdi we created above
    - "/mnt/sdb1/etc/gitlab/:/etc/gitlab"
    - "/mnt/sdb1/var/log/gitlab:/var/log/gitlab"
    - "/mnt/sdb1/var/opt/gitlab:/var/opt/gitlab"
    # This volume sits in the shared folder defined above
    - "/gitlabbackups:/var/opt/gitlab/backups"
    cap_add:
    # These seem to be necessary for the mounted drive to work properly
    # https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities
    - SYS_ADMIN
    - DAC_READ_SEARCH

    由于自动安装vdi似乎存在问题,因此请使用启动脚本(例如,假设您使用的是D驱动器,只需根据需要替换<...>中的任何内容),请示例run.bat:
    @cd /d D:\<path to docker-compose.yml, assuming it's on the D drive>
    @docker-machine start <docker machine name>
    @FOR /f "tokens=*" %%i IN ('docker-machine env <docker machine name>') DO @%%i
    @docker-machine ssh <docker machine name> sudo mount /dev/sdb1 /mnt/sdb1
    @docker-compose build
    @docker-compose up -d
    @REM If the docker machine was completely off, running only 'docker-compose up -d' will
    @REM not mount the volumes properly. Stopping and restarting the container results in
    @REM the volumes mounting properly.
    @docker stop <gitlab container name>
    @docker start <gitlab container name>
    @pause

    注意:gitlab容器名称可以通过运行 docker-compose up一次然后通过 docker ps -a进行检查来找到,但是通常遵循 <directory compose file is in>_<name in the compose file, e.g. gitlab here>_1约定

    假设一切顺利,并且根据您的情况更改上述<...>中的内容,您应该能够运行批处理文件并启动gitlab并以将所有内容存储在备用驱动器上的方式运行,vdi中的持久性工作文件(以解决VBox POSIX的限制),以及备份透明地存储在共享文件夹中。

    希望这可以帮助其他尚未使用本地docker的可怜人。

    关于docker - 在Windows主机上使用Docker设置Gitlab,共享文件夹出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45134978/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com