当前位置: 首页 > 工具软件 > Gitlab Shell > 使用案例 >

windows 使用docker搭建gitlab遇到坑和解决方案

贡和裕
2023-12-01

I think I have a solution for running Gitlab from Docker on Windows 10; it appears to be working for me thus far.

For all of the Powershell, you'll need an elevated prompt.

Init

This first part gets the folders/volumes setup, then creates and starts the Gitlab container. (Remember that you have to have the Docker Desktop running and tell it to make the C drive shared.)

mkdir c:\GitlabConfig
mkdir c:\GitlabConfig\backups

docker volume create gitlab-logs
docker volume create gitlab-data 
docker run --detach `
    --name gitlab `
    --restart always `
    --hostname gitlab.local `
    --publish 4443:443 --publish 4480:80 --publish 8222:22 `
    --volume C:\GitlabConfig:/etc/gitlab `
    --volume gitlab-logs:/var/log/gitlab `
    --volume gitlab-data:/var/opt/gitlab `
    gitlab/gitlab-ce

Wait a few minutes for Gitlab to finish initializing; just keep refreshing "localhost:4480/" in a browser until the web page comes up.

You can now use Gitlab however you were planning.

Backups

Edit the c:\GitlabConfig\gitlab.rb file. Find the 2 settings indicated, uncomment, and set them like so (this is what you'll end up with):

gitlab_rails['manage_backup_path'] = false

gitlab_rails['backup_path'] = "/etc/gitlab/backups"

Note that the "backups" folder is the same one created on the host back at the beginning, just how it's known inside the container.

Next, restart the container.

docker restart gitlab

Now you can backup Gitlab and it'll show up on the Windows host

docker exec -it gitlab gitlab-rake gitlab:backup:create

You will see a c:\GitlabConfig\backups\{prefix}_gitlab_backup.tar file in Windows after the process completes.

Restores

Once everything's ready for a restore, you can just run

gitlab gitlab-rake gitlab:backup:restore BACKUP={prefix}

Where {prefix} is everything that comes before the "_gitlab_backup.tar" of the filename you want to use for the restore. The restore functionality looks in the folder you configured earlier in the gitlab.rb file.

With this approach, I've been able to setup a running Gitlab container on Windows 10. I can just backup that main "c:\GitlabConfig" folder using any method I like.

Additionally, you can nuke the container and the 2 docker-volumes and start from scratch with just that folder's contents. If you start the new container by pointing it to your saved config folder, it'll have most of your stuff right out of the gate. But after it's done booting up, you can restore a backup and you'll be right back where you were. The docs presently indicate that there's problems with restoring when Gitlab is running in a container, but I didn't have any. If the restore runs into trouble, it should tell you what you need to fix before trying again

 类似资料: