Empty gitlab state after container restart

I am running docker via docker compose.
(https://docs.gitlab.com/ee/install/docker.html#install-gitlab-using-docker-compose)

This is docker-compose.yml content:

version: '3.6'
services:
  web:
    image: 'gitlab/gitlab-ee:latest'
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.example.com:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2224
    ports:
      - '8929:80'
      - '2224:22'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    shm_size: '256m'

I am getting empty gitlab state after container restart:

  • root password is reset (regenerated)
  • no repositories available

How to avoid this?
Should I use backup before every container stop?

I think you should have downloaded the example file from the link you posted, since:

web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://gitlab.example.com'
  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'

as you can see, the volumes section is mapping /etc/gitlab, /var/log/gitlab and /var/opt/gitlab to directories that exist on the machine where you are running docker so in /srv/gitlab/. Since you didn’t map it properly, every time you destroy the container you lose the paths to your config, data and logs.

If you don’t want to map shared storage to /srv/gitlab/wherever then you can change it accordingly. I guess it depends on your docker usage requirements.

1 Like

You gave me an idea.

The problem was in the GITLAB_HOME variable.
Its value was set incorrectly in .env.yml:
GITLAB_HOME="C:\gitlab"

Because on Windows its value should be set like this:
GITLAB_HOME="/c/gitlab"

Advice: use docker-compose config to check settings.

1 Like