Public Repository

Last pushed: 4 months ago
Short Description
Dockerized Gitlab with a lot of configurable options. See https://gotfix.com/docker/gitlab
Full Description

gotfix/gitlab:9.3.9

Alternatively image is available from quay.io quay.io/gotfix/gitlab:9.3.9

Canonical source

The canonical source of the repository is hosted on gotfix.com.


Table of Content

Other References

Introduction

Dockerfile to build a GitLab image for the Docker opensource container platform.

GitLab CE is set up in the Docker image using the install from source method as documented in the official GitLab documentation.

For other methods to install GitLab please refer to the Official GitLab Installation Guide which includes a GitLab image for Docker.

Contributing

If you find this image useful here's how you can help:

  • Send a Pull Request with your awesome new features and bug fixes
  • Be a part of the community and help resolve Issues

Team

See Contributors for the complete list developers that have contributed to this project.

Issues

Docker is a relatively new project and is active being developed and tested by a thriving community of developers and testers and every release of docker features many enhancements and bugfixes.

Given the nature of the development and release cycle it is very important that you have the latest version of docker installed because any issue that you encounter might have already been fixed with a newer docker release.

Install the most recent version of the Docker Engine for your platform using the official Docker releases, which can also be installed using:

wget -qO- https://get.docker.com/ | sh

Fedora and RHEL/CentOS users should try disabling selinux with setenforce 0 and check if resolves the issue. If it does than there is not much that I can help you with. You can either stick with selinux disabled (not recommended by redhat) or switch to using ubuntu.

You may also set DEBUG=true to enable debugging of the entrypoint script, which could help you pin point any configuration issues.

If using the latest docker version and/or disabling selinux does not fix the issue then please file an issue request on the issues page.

In your issue report please make sure you provide the following information:

  • The host distribution and release version.
  • Output of the docker version command
  • Output of the docker info command
  • The docker run command you used to run the image (mask out the sensitive bits).

Installation

Prerequisites

Your docker host needs to have 2GB or more of available RAM to run GitLab. Please refer to the GitLab hardware requirements documentation for additional information. Note that those requirements might be outdated and not always based on the real data, so take precautions. It is always safer to slightly over provision capacity than have less than required.

Preparing container image

Automated builds of the image are available from Dockerhub and is the recommended method of installation.

docker pull gotfix/gitlab:9.3.9

You can also pull the latest tag which is built from the repository HEAD

docker pull gotfix/gitlab:latest

Alternatively you can build the image locally.

docker build -t gotfix/gitlab gotfix.com/docker/gitlab

Quick Start

The quickest way to get started is using docker-compose.

wget https://gotfix.com/docker/gitlab/raw/master/docker-compose.yml

Generate random strings that are at least 64 characters long for each of GITLAB_SECRETS_OTP_KEY_BASE, GITLAB_SECRETS_DB_KEY_BASE, and GITLAB_SECRETS_SECRET_KEY_BASE. These values are used for the following:

  • GITLAB_SECRETS_OTP_KEY_BASE is used to encrypt 2FA secrets in the database. If you lose or rotate this secret, none of your users will be able to log in using 2FA.
  • GITLAB_SECRETS_DB_KEY_BASE is used to encrypt CI secret variables, as well as import credentials, in the database. If you lose or rotate this secret, you will not be able to use existing CI secrets.
  • GITLAB_SECRETS_SECRET_KEY_BASE is used for password reset links, and other 'standard' auth features. If you lose or rotate this secret, password reset tokens in emails will reset.

Tip: You can generate a random string using pwgen -Bsv1 64 and assign it as the value of GITLAB_SECRETS_DB_KEY_BASE.

Start GitLab using:

docker-compose up

Alternatively, you can manually launch the gitlab container and the supporting postgresql and redis containers by following this three step guide.

Step 1. Launch a postgresql container

docker run --name gitlab-postgresql -d \
    --env 'DB_NAME=gitlabhq_production' \
    --env 'DB_USER=gitlab' --env 'DB_PASS=password' \
    --env 'DB_EXTENSION=pg_trgm' \
    --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \
    gotfix/postgresql:latest

Step 2. Launch a redis container

docker run --name gitlab-redis -d \
    --volume /srv/docker/gitlab/redis:/var/lib/redis \
    gotfix/redis:latest

Step 3. Launch the gitlab container

docker run --name gitlab -d \
    --link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
    --publish 10022:22 --publish 10080:8181 \
    --env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
    --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
    --env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \
    --env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

Please refer to Available Configuration Parameters to understand GITLAB_PORT and other configuration options

NOTE: Please allow a couple of minutes for the GitLab application to start.

Point your browser to http://localhost:10080 and set a password for the root user account.

You should now have the GitLab application up and ready for testing. If you want to use this image in production then please read on.

The rest of the document will use the docker command line. You can quite simply adapt your configuration into a docker-compose.yml file if you wish to do so.

Configuration

Caddy (front-end web-server)

GitLab uses gitlab-workhorse to accept HTTP connection, and it is expecting to receive those connections via reveres-proxy, such as Caddy (or nginx). Since NGINX is no longer present in this container image, we will use Caddy for GitLab to handle those. For a complete list of configuration parameters, you should read here. In this section we will only cover minimum steps to get you started.

If you are using plain docker (not docker-compose), the follwoing --env settings will be required to run GitLab (similar setting are available for Pages and Registry):

$ docker run -d \
    --link=gitlab:gitlab \
    --env="GITLAB_HOST=gitlab.example.com" \
    --env="TLS_AGREE=true" \
    --env="CADDY_EMAIL=admin@example.com" \
    -v $HOME/.caddy:/root/.caddy \
    -v $HOME/caddy/logs:/var/log/caddy \
    -p 80:80 -p 443:443 \
    gotfix/caddy:latest-gitlab

For docker-compose, you will have to configure something similar to the following:

  caddy:
    restart: always
    image: gotfix/caddy:latest-gitlab
    depends_on:
    - gitlab # Ensures that caddy will relink if gitlab container is restarted
    command:
    - -quic
    ports:
    - 80:80
    - 443:443
    environment:
    - TLS_AGREE=true # Indicates that you have read and agree to the Let's Encrypt Subscriber Agreement.
    - CADDY_EMAIL=admin@example.com # Make sure this email is yours and reachable
    - GITLAB_HOST=gitlab.example.com # Hostname of the GitLab installation that this server is reachable at
    - GITLAB_IP=gitlab # IP/Hostname of the running Gitlab service. This assume that Gitlab is configured in the same `services:` section under name gitlab.
    volumes:
    - ./.caddy:/root/.caddy # Your certificates will be stored here
    - ./gitlab/caddy/logs:/var/log/caddy:Z # Caddy logs will be stored here

See example gitlab docker-compose for a more complete file.

Data Store

GitLab is a code hosting software and as such you don't want to lose your code when the docker container is stopped/deleted. To avoid losing any data, you should mount a volume at,

  • /home/git/data

Note that if you are using the docker-compose approach, this has already been done for you.

SELinux users are also required to change the security context of the mount point so that it plays nicely with selinux.

mkdir -p /srv/docker/gitlab/gitlab
sudo chcon -Rt svirt_sandbox_file_t /srv/docker/gitlab/gitlab

Volumes can be mounted in docker by specifying the -v option in the docker run command.

docker run --name gitlab -d \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

Database

GitLab uses a database backend to store its data. You can configure this image to use either MySQL or PostgreSQL.

Note: GitLab HQ recommends using PostgreSQL over MySQL

PostgreSQL

External PostgreSQL Server

The image also supports using an external PostgreSQL Server. This is also controlled via environment variables.

CREATE ROLE gitlab with LOGIN CREATEDB PASSWORD 'password';
CREATE DATABASE gitlabhq_production;
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab;

Additionally since GitLab 8.6.0 the pg_trgm extension should also be loaded for the gitlabhq_production database.

We are now ready to start the GitLab application.

Assuming that the PostgreSQL server host is 192.168.1.100

docker run --name gitlab -d \
    --env 'DB_ADAPTER=postgresql' --env 'DB_HOST=192.168.1.100' \
    --env 'DB_NAME=gitlabhq_production' \
    --env 'DB_USER=gitlab' --env 'DB_PASS=password' \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9
Linking to PostgreSQL Container

You can link this image with a postgresql container for the database requirements. The alias of the postgresql server container should be set to postgresql while linking with the gitlab image.

If a postgresql container is linked, only the DB_ADAPTER, DB_HOST and DB_PORT settings are automatically retrieved using the linkage. You may still need to set other database connection parameters such as the DB_NAME, DB_USER, DB_PASS and so on.

To illustrate linking with a postgresql container, we will use the gotfix/postgresql image. When using postgresql image in production you should mount a volume for the postgresql data store. Please refer the README of docker-postgresql for details.

First, lets pull the postgresql image from the docker index.

docker pull gotfix/postgresql:latest

For data persistence lets create a store for the postgresql and start the container.

SELinux users are also required to change the security context of the mount point so that it plays nicely with selinux.

mkdir -p /srv/docker/gitlab/postgresql
sudo chcon -Rt svirt_sandbox_file_t /srv/docker/gitlab/postgresql

The run command looks like this.

docker run --name gitlab-postgresql -d \
    --env 'DB_NAME=gitlabhq_production' \
    --env 'DB_USER=gitlab' --env 'DB_PASS=password' \
    --env 'DB_EXTENSION=pg_trgm' \
    --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \
    gotfix/postgresql:latest

The above command will create a database named gitlabhq_production and also create a user named gitlab with the password password with access to the gitlabhq_production database.

We are now ready to start the GitLab application.

docker run --name gitlab -d --link gitlab-postgresql:postgresql \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

Here the image will also automatically fetch the DB_NAME, DB_USER and DB_PASS variables from the postgresql container as they are specified in the docker run command for the postgresql container. This is made possible using the magic of docker links and works with the following images:

MySQL

Please read this document to understand complexity involved with MySQL and Gitlab. You might need to take some of the manual steps to have installation or upgrade work correctly. Also see docker/gitlab#81 for what support is implemented.

External MySQL Server

The image can be configured to use an external MySQL database. The database configuration should be specified using environment variables while starting the GitLab image.

Before you start the GitLab image create user and database for gitlab.

CREATE USER 'gitlab'@'%.%.%.%' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT ALL PRIVILEGES ON `gitlabhq_production`.* TO 'gitlab'@'%.%.%.%';

We are now ready to start the GitLab application.

Assuming that the mysql server host is 192.168.1.100

docker run --name gitlab -d \
    --env 'DB_ADAPTER=mysql2' --env 'DB_HOST=192.168.1.100' \
    --env 'DB_NAME=gitlabhq_production' \
    --env 'DB_USER=gitlab' --env 'DB_PASS=password' \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9
Linking to MySQL Container

You can link this image with a mysql container for the database requirements. The alias of the mysql server container should be set to mysql while linking with the gitlab image.

If a mysql container is linked, only the DB_ADAPTER, DB_HOST and DB_PORT settings are automatically retrieved using the linkage. You may still need to set other database connection parameters such as the DB_NAME, DB_USER, DB_PASS and so on.

To illustrate linking with a mysql container, we will use the MariaDB image. When using docker-mysql in production you should mount a volume for the mysql data store.

First, lets pull the mysql image from the docker index.

docker pull mariadb:latest

For data persistence lets create a store for the mysql and start the container.

SELinux users are also required to change the security context of the mount point so that it plays nicely with selinux.

mkdir -p /srv/docker/gitlab/mysql
sudo chcon -Rt svirt_sandbox_file_t /srv/docker/gitlab/mysql

The run command looks like this.

docker run --name gitlab-mysql \
    --volume /srv/docker/gitlab/mysql:/var/lib/mysql \
    --env='MYSQL_DATABASE=gitlabhq_production' \
    --env='MYSQL_USER=gitlab' \
    --env='MYSQL_PASSWORD=password' \
    --env='MYSQL_RANDOM_ROOT_PASSWORD=yes' \
    -d mariadb:latest \
    --character-set-server=utf8 \
    --collation-server=utf8_unicode_ci \
    --innodb-file-format=barracuda \
    --innodb-file-per-table=1 \
    --innodb-large-prefix=1 \
    --default-storage-engine=InnoDB

The above command will create a database named gitlabhq_production and also create a user named gitlab with the password password with full/remote access to the gitlabhq_production database.

We are now ready to start the GitLab application.

docker run --name gitlab -d --link gitlab-mysql:mysql \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

Redis

GitLab uses the redis server for its key-value data store. The redis server connection details can be specified using environment variables.

External Redis Server

The image can be configured to use an external redis server. The configuration should be specified using environment variables while starting the GitLab image.

Assuming that the redis server host is 192.168.1.100

docker run --name gitlab -it --rm \
    --env 'REDIS_HOST=192.168.1.100' --env 'REDIS_PORT=6379' \
    gotfix/gitlab:9.3.9

Linking to Redis Container

You can link this image with a redis container to satisfy gitlab's redis requirement. The alias of the redis server container should be set to redisio while linking with the gitlab image.

To illustrate linking with a redis container, we will use the gotfix/redis image. Please refer the README of docker-redis for details.

First, lets pull the redis image from the docker index.

docker pull gotfix/redis:latest

Lets start the redis container

docker run --name gitlab-redis -d \
    --volume /srv/docker/gitlab/redis:/var/lib/redis \
    gotfix/redis:latest

We are now ready to start the GitLab application.

docker run --name gitlab -d --link gitlab-redis:redisio \
    gotfix/gitlab:9.3.9

Mail

The mail configuration should be specified using environment variables while starting the GitLab image. The configuration defaults to using gmail to send emails and requires the specification of a valid username and password to login to the gmail servers.

If you are using Gmail then all you need to do is:

docker run --name gitlab -d \
    --env 'SMTP_USER=USER@gmail.com' --env 'SMTP_PASS=PASSWORD' \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

Please refer the Available Configuration Parameters section for the list of SMTP parameters that can be specified.

Reply by email

Since version 8.0.0 GitLab adds support for commenting on issues by replying to emails.

To enable this feature you need to provide IMAP configuration parameters that will allow GitLab to connect to your mail server and read mails. Additionally, you may need to specify GITLAB_INCOMING_EMAIL_ADDRESS if your incoming email address is not the same as the IMAP_USER.

If your email provider supports email sub-addressing then you should add the +%{key} placeholder after the user part of the email address, eg. GITLAB_INCOMING_EMAIL_ADDRESS=reply+%{key}@example.com. Please read the documentation on reply by email to understand the requirements for this feature.

If you are using Gmail then all you need to do is:

docker run --name gitlab -d \
    --env 'IMAP_USER=USER@gmail.com' --env 'IMAP_PASS=PASSWORD' \
    --env 'GITLAB_INCOMING_EMAIL_ADDRESS=USER+%{key}@gmail.com' \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

Please refer the Available Configuration Parameters section for the list of IMAP parameters that can be specified.

Enabling HTTPS support

HTTPS support can be enabled by setting the GITLAB_HTTPS option to true.

docker run --name gitlab -d \
    --publish 10022:22 --publish 10080:8181 \
    --env 'GITLAB_SSH_PORT=10022' --env 'GITLAB_PORT=443' \
    --env 'GITLAB_HTTPS=true' \
    --volume /srv/docker/gitlab/gitlab:/home/git/data \
    gotfix/gitlab:9.3.9

In this configuration, any requests made over the plain http protocol will automatically be redirected to use the https protocol.

Using HTTPS with a load balancer

Load balancers like nginx/haproxy/hipache talk to backend applications over plain http and as such the installation of ssl keys and certificates are not required and should NOT be installed in the container. The SSL configuration has to instead be done at the load balancer.

However, when using a load balancer you MUST set GITLAB_HTTPS to true.

Wit

Docker Pull Command
Owner
gotfix