Self-managed gitlab-ce in docker: how to link host machine gitlab.rb and gitlab.rb in docker container?

Hello, GitLab community. I have a question about self-managed GitLab-CE in Docker. I want to know how to link the host machine gitlab.rb and the gitlab.rb in the Docker container.

I have created a Docker container with a running GitLab instance using docker-compose.yml as follows:

version: '3.8'
services:
gitlab-ce:
image: gitlab/gitlab-ce:latest
ports:
- "8880:80/tcp"
- "8443:443/tcp"
- "8222:22/tcp"
volumes:
- '/home/userme/.gitlab/etc:/etc/gitlab'
- '/home/userme/.gitlab/var/log:/var/log/gitlab'
- '/home/userme/.gitlab/var/opt:/var/opt/gitlab'

In the folder ~/.gitlab/etc, I have a file gitlab.rb, but this file is not related to the running Docker container /etc/gitlab.rb file. So, if I want to change the config, I need to do docker exec containername bash to edit the real config. How can I link these two files so that I can edit gitlab.rb on the host machine, not in the Docker container only?
if i add - '/home/userme/.gitlab/etc/gitlab.rb:/etc/gitlab/gitlab.rb' and then stop docker and do docker-compose up, does it destruct existing repos in docker?

No, but it won’t be visible, because you will mount over it (standard Linux stuff).

Copy the existing content of /etc/gitlab from the running container to local /home/userme/.gitlab/etc. You can use docker cp '<container_id>:/etc/gitlab/.' /home/userme/.gitlab/etc to copy the whole directory.

After you are sure you have the running config/files in your directory update your volumes definition by removing the quotes (I have never used single quotes, might be not supported?).

volumes:
- /home/userme/.gitlab/etc:/etc/gitlab

You can do the same with the other folders if needed.

2 Likes

thanks to @balonik for good advice to backup current active docker /etc/ stuff with docker cp