sameersbn / docker-gitlab

Dockerized GitLab
http://www.damagehead.com/docker-gitlab/
MIT License
7.9k stars 2.14k forks source link

Store repositories on external volume #1317

Open wokadeh opened 7 years ago

wokadeh commented 7 years ago

Hello together,

I would like to store the content of my gitlab externally. However, the repositories are not stored within the docker container nor in the external path. I cannot find them anywhere. But new projects can be created.

I create the container like this:

docker run \
--name gitlab2_app \
--hostname xxx\
--link gitlabN-postgresql:postgresql \
--link gitlabN-redis:redisio \
--publish 2289:22 \
--publish 8929:80 \
--userns=host \
--privileged \
--restart=always \
-e 'GITLAB_REPOS_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/repositories' \
-e 'GITLAB_BUILDS_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/builds' \
-e 'GITLAB_BACKUP_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/backups' \
-e 'GITLAB_DOWNLOADS_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/downloads' \
-e 'GITLAB_SHARED_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/shared' \
-e 'GITLAB_ARTIFACTS_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/artifacts' \
--volume /home/xxx/external_storage/docker/volumes/diva_gitlab/data:/home/git/data \
--volume /home/xxx/external_storage/docker/volumes/diva_gitlab/log:/var/log/gitlab \
sameersbn/gitlab:latest

1) What do I have to change that my gitlab starts using the external directory? 2) From another gitlab installation I have some user folders in a repository directory, that I would like to move to my new installation. However, that old gitlab installation is not working anymore and I would like to transfer these repositories to the new installation. Is that possible?

cpuschma commented 7 years ago

However, the repositories are not stored within the docker container nor in the external path

Repositories are stored in /home/git/data/repositories. I personally recommend you to use docker-compose (Quick Start)

Instead of seperating the repository from the data you should probably save all of the data on your external storage (including your database if you want to). Modify the volume path in your docker-compose file:

  gitlab:
    restart: always
    image: sameersbn/gitlab:9.4.3
    volumes:
    - /home/xxx/external_storage/docker/volumes/diva_gitlab/:/home/git/data:Z
wokadeh commented 7 years ago

Thank you for your answer. Yes, usually the repos are stored within /home/git/data/repositories, though through my setup they seem to be somewhere else which is not this path in the container and not the path I intended on my external drive.

What does the ":Z" stand for?

What advantage do I have with a compose file? It is important for me that the containers are loaded on a reboot of the machine so I was using a systemd service that is loading the containers for me.

cpuschma commented 7 years ago

What advantage do I have with a compose file? It is important for me that the containers are loaded on a reboot of the machine so I was using a systemd service that is loading the containers for me.

Docker-Compose is a tool for defining and running multi-container Docker applications. You don't need to enter a long command everytime you want to create a container. You can simply specify your settings your your docker-compose file and run docker-compose up

To run a docker-compose on startup you can either use crontab @reboot /usr/local/bin/docker-compose -f /path/to/docker-compose.yml -d (start in daemon mode) or change your systemd service file ExecStart parameter to:

ExecStart=/usr/local/bin/docker-compose -f /path/to/docker-compose.yml

(You don't need daemon-mode when using systemd) Ensure that the user in your service file has permissions to use docker

// edit: The 'Z' option tells Docker to label the content with a private unshared label.

And you could use

find -type d -name 'repositories'

to find the repository folder in your setup

wokadeh commented 7 years ago

So, what is a private unshared label?

Yes, I used 'find' also looking directly for the name of some of the repos to find them, but I didn't get a result. Really weird since they are there somewhere according to the web interface.

So, when I setup a new gitlab instance is it possible to migrate the single *.git directories from my old instance to this? I didn't make a backup, unfortunaly, I will change to auto-backup with the given flag in the new container.

wokadeh commented 7 years ago

So I did use docker-compose and used

Instead of seperating the repository from the data you should probably save all of the data on your external storage (including your database if you want to). Modify the volume path in your docker-compose file:

gitlab:
    restart: always
    image: sameersbn/gitlab:9.4.3
    volumes:
    - /home/xxx/external_storage/docker/volumes/diva_gitlab/:/home/git/data:Z

I also set the variable - GITLAB_REPOS_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/repositories

What happens now is that inside the docker container now that path is created and repositories are stored there :-( :-(

The reason I also used the variable was that the repositories where still stored at the usual location, e.g. the volume was not used

avluis commented 7 years ago

Have you resolved your issue? -- I think I can see what's going on.

From your opening post -- this is no good: -e 'GITLAB_REPOS_DIR=/home/xxx/external_storage/docker/volumes/diva_gitlab/data/repositories' But this is: -e 'GITLAB_REPOS_DIR=/home/git/data/repositories'

Here is how I would do what you are trying to accomplish (and a few additional entries for good measure):

docker run --name="gitlab" --net="none" -e TZ="America/Chicago" -e HOST_OS="unRAID" \
-v "/mnt/user/appdata/gitlab/":"/home/git/data":rw \
-v "/mnt/user/appdata/gitlab/certs/":"/certs":rw \
-v "/mnt/user/appdata-store/gitlab/backups/":"/home/git/data/backups":rw \
-v "/mnt/user/appdata-store/gitlab/repositories/":"/home/git/data/repositories":rw \
-v "/mnt/user/appdata-store/gitlab/shared/lfs-objects/":"/home/git/data/shared/lfs-objects":rw \
-v "/mnt/user/appdata-store/gitlab/shared/registry/":"/home/git/data/shared/registry":rw \
--network <DOCKER_NET> --ip <GITLAB_IP> --hostname='gitlab' \
--env-file /mnt/user/appdata/gitlab/DockerEnv sameersbn/gitlab

Ignore everything else but the volume mounts. I am defining my variables in an environment file (--env-file /mnt/user/appdata/gitlab/DockerEnv) -- the ones you are seeing in the above command are inserted by Docker.

Note that I do not have a single variable defined for path data -- I simply remap volume mounts.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any activity for the last 60 days. It will be closed if no further activity occurs during the next 7 days. Thank you for your contributions.