- Users interested in installing GitLab via Docker Compose
- Users who use sudo with Docker, rather than running Docker commands as root
Environment variables aren’t passed to Docker when you issue a command like “sudo docker compose up -d”. The GitLab installation specifies that you should use an environment variable ($GITLAB_HOME) for installation, rather than defining the path directly.
If you have followed the GitLab instructions, you will issue the below command to set the environment variable:
This variable isn’t going to be passed to Docker though when you try to bring up your containers using Compose.
When you attempt to bring up your Compose file, you receive the following error:
> sudo docker compose up -d WARNING: The GITLAB_HOME variable is not set. Defaulting to a blank string.
The problem was that your environment variable previously set wasn’t passed to Docker when you used sudo.
Option 1 – Pass the “-E” option
Sudo has an option to pass “-E” or “–preserve-env” which will retain the environment variables that you set. Therefore, to bring up your Docker Compose file, you can issue the command:
sudo -E docker compose up -d
This will ensure the variable GITLAB_HOME is correctly passed to Compose.
Option 2 – Permanently Add GITLAB_HOME
First, you’ll need to modify your user profile. Use any text editor to modify ~/.profile. For example:
Add the following line to the bottom of the profile file, substituting where you would like the GitLab files to live. I chose /srv/:
Now modify the sudoers file so this variable is always passed when using sudo:
Add the following lines to the file:
# This preserves the GITLAB_HOME variable for Docker Defaults env_keep += "GITLAB_HOME"
That’s it. Now you can use sudo for Docker Compose without having to remember to pass the -E option.