dockerized GitLab 数据卷的移动位置

Moving location of dockerized GitLab data volumes

我 运行 GitLab 使用找到的 8.11.0-ce.1 图像 here。我这样配置 docker-compose 卷:

  volumes:
    - './data/config:/etc/gitlab'
    - './data/logs:/var/log/gitlab'
    - './data/data:/var/opt/gitlab'

但是这个磁盘的大小有限,我想将这些卷移动到更大的 /data/gitlab/ 目录。

为此,我尝试了以下步骤: 1. 关闭 docker 容器 2.复制数据卷过来(cp -r /app/gitlab/data/ /data/gitlab) 3.修改docker-compose.yml为

  volumes:
    - '/data/gitlab/config:/etc/gitlab'
    - '/data/gitlab/logs:/var/log/gitlab'
    - '/data/gitlab/data:/var/opt/gitlab'

但是,在重新启动容器后,我收到一个不断重复的错误(见下文)。我假设必须遵循额外的步骤?还是我做错了?

gitlab_1  | Preparing services...
gitlab_1  | Starting services...
gitlab_1  | Configuring GitLab package...
gitlab_1  | Configuring GitLab...
gitlab_1  | /opt/gitlab/embedded/bin/runsvdir-start: line 24: ulimit: pending signals: cannot modify limit: Operation not permitted
gitlab_1  | /opt/gitlab/embedded/bin/runsvdir-start: line 34: ulimit: max user processes: cannot modify limit: Operation not permitted
gitlab_1  | /opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system
gitlab_1  |
gitlab_1  | ================================================================================
gitlab_1  | Error executing action `run` on resource 'execute[/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions]'
gitlab_1  | ================================================================================
gitlab_1  |
gitlab_1  | Mixlib::ShellOut::ShellCommandFailed
gitlab_1  | ------------------------------------
gitlab_1  | Expected process to exit with [0], but received '1'
gitlab_1  | ---- Begin output of /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions ----
gitlab_1  | STDOUT:
gitlab_1  | STDERR: /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:703:in `initialize': Permission denied @ rb_sysopen - /var/log/gitlab/gitlab-shell/gitlab-shell.log (Errno::EACCES)
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:703:in `open'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:703:in `open_logfile'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:695:in `set_dev'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:635:in `initialize'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:353:in `new'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/2.3.0/logger.rb:353:in `initialize'
gitlab_1  |     from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_logger.rb:15:in `new'
gitlab_1  |     from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_logger.rb:15:in `<top (required)>'
gitlab_1  |     from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_keys.rb:4:in `require_relative'
gitlab_1  |     from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_keys.rb:4:in `<top (required)>'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
gitlab_1  |     from /opt/gitlab/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
gitlab_1  |     from /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys:24:in `<main>'
gitlab_1  | ---- End output of /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions ----
gitlab_1  | Ran /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions returned 1
gitlab_1  |
gitlab_1  | Resource Declaration:
gitlab_1  | ---------------------
gitlab_1  | # In /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/gitlab-shell.rb
gitlab_1  |
gitlab_1  | 124: execute "#{gitlab_shell_keys_check} check-permissions" do
gitlab_1  | 125:   user git_user
gitlab_1  | 126:   group git_group
gitlab_1  | 127: end
gitlab_1  | 128:
gitlab_1  |
gitlab_1  | Compiled Resource:
gitlab_1  | ------------------
gitlab_1  | # Declared in /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/gitlab-shell.rb:124:in `from_file'
gitlab_1  |
gitlab_1  | execute("/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions") do
gitlab_1  |   action [:run]
gitlab_1  |   retries 0
gitlab_1  |   retry_delay 2
gitlab_1  |   default_guard_interpreter :execute
gitlab_1  |   command "/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions"
gitlab_1  |   backup 5
gitlab_1  |   group "git"
gitlab_1  |   returns 0
gitlab_1  |   user "git"
gitlab_1  |   declared_type :execute
gitlab_1  |   cookbook_name "gitlab"
gitlab_1  |   recipe_name "gitlab-shell"
gitlab_1  | end
gitlab_1  |
gitlab_1  | Platform:
gitlab_1  | ---------
gitlab_1  | x86_64-linux
gitlab_1  |

TL;DR - 尝试使用 cp -a 而不是 cp -r

详情:

我使用 https://docs.gitlab.com/omnibus/docker/#install-gitlab-using-docker-compose 上的撰写文件快速完成了此操作。我确实看到了和你一样的错误。这显然看起来是某种许可问题。我注意到容器启动时有一个方便的提示,说:

# docker-compose up
Recreating gitlab2_web_1
Attaching to gitlab2_web_1
web_1  | Thank you for using GitLab Docker Image!
web_1  | Current version: gitlab-ce=8.11.5-ce.0
web_1  |
web_1  | Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
web_1  | And restart this container to reload settings.
web_1  | To do it use docker exec:
web_1  |
web_1  |   docker exec -it gitlab vim /etc/gitlab/gitlab.rb
web_1  |   docker restart gitlab
web_1  |
web_1  | For a comprehensive list of configuration options please see the Omnibus GitLab readme
web_1  | https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
web_1  |
web_1  | If this container fails to start due to permission problems try to fix it by executing:
web_1  |
web_1  |   docker exec -it gitlab update-permissions
web_1  |   docker restart gitlab
web_1  |
web_1  | Preparing services...
web_1  | Starting services...

我尝试了这个,但取得了一些有限的成功……如图所示 运行 有点棘手,因为容器不断重新启动。由于您 运行ning 通过撰写,您可以添加:

entrypoint: update-permissions

即像这样:

web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.example.com'
  entrypoint: update-permissions
  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'

到相关的服务配置。它会重新创建容器,但没关系。然而,对我来说,在我这样做之后,我似乎仍然对 redis 有一些问题。

虽然这只是磁盘上的文件,但我想我会在复制时保留所有权等,这似乎工作正常。在你的情况下,我猜是:

cp -a /app/gitlab/data/ /data/gitlab

这些是我移动位置的 contenerized GitLab 的步骤:

  1. 运行新建GitLab实例,例如:

    docker run --detach \
        --hostname gitlab.example.com \
        --publish 443:443 --publish 80:80 --publish 22:22 \
        --name gitlab \
        --restart always \
        --volume /srv/gitlab/config:/etc/gitlab \
        --volume /srv/gitlab/logs:/var/log/gitlab \
        --volume /srv/gitlab/data:/var/opt/gitlab \
        gitlab/gitlab-ce:latest
    
  2. 片刻后停止容器中所需的服务,以避免冲突:

    docker exec -it gitlab /bin/bash -c 'gitlab-ctl stop unicorn && gitlab-ctl stop sidekiq && gitlab-ctl stop'
    
  3. 复制重要数据和配置文件夹到新的GitLab 来自旧 GitLab 的容器。假设你的新 GitLab 容器 它被称为 gitlab 并且您的旧 GitLab 卷位置是 /srv/(参考步骤1中我的卷位置):

    docker exec -it -u git gitlab /bin/bash -c 'rsync -avz user@SERVER_LOCATION:/srv/gitlab/config/* /etc/gitlab/'
    docker exec -it -u git gitlab /bin/bash -c 'rsync -avz user@SERVER_LOCATION:/srv/gitlab/logs/* /var/log/gitlab/'
    docker exec -it -u git gitlab /bin/bash -c 'rsync -avz user@SERVER_LOCATION:/srv/gitlab/data/* /var/opt/gitlab/
    

    (将 SERVER_LOCATION 替换为您的位置服务器。如果您在同一台机器上有文件,请使用 docker cp 命令。)

  4. 重启你的容器:

    docker restart gitlab
    
  5. 几秒钟后(大约 20。取决于您的机器)更新 权限文件:

    docker exec -it gitlab /bin/bash -c "chown -R git /var/opt/gitlab/gitlab-rails/uploads && find /var/opt/gitlab/gitlab-rails/uploads -type f -exec chmod 0644 {} \; && find /var/opt/gitlab/gitlab-rails/uploads -type d -not -path /var/opt/gitlab/gitlab-rails/uploads -exec chmod 0700 {} \;"
    docker exec -it gitlab /bin/bash -c 'update-permissions'
    

    检查是否正确工作:

    docker exec -it gitlab /bin/bash -c 'gitlab-rake gitlab:check SANITIZE=true'
    

    (如果在此步骤中 return 有任何错误,请阅读消息并应用建议。)

  6. 生成初始迁移的备份(如果需要):

    docker exec -it gitlab /bin/bash -c 'gitlab-rake gitlab:backup:create'