Sign inSign up

builtdock/docker-gitlab

By builtdock

Updated almost 11 years ago

Image
0

288

builtdock/docker-gitlab repository overview

Table of Contents

Introduction

Dockerfile to build a GitLab container image.

Version

Current Version: 7.2.2

Hardware Requirements

CPU

  • 1 core works for under 100 users but the responsiveness might suffer
  • 2 cores is the recommended number of cores and supports up to 100 users
  • 4 cores supports up to 1,000 users
  • 8 cores supports up to 10,000 users

Memory

  • 512MB is too little memory, GitLab will be very slow and you will need 250MB of swap
  • 768MB is the minimal memory size but we advise against this
  • 1GB supports up to 100 users (with individual repositories under 250MB, otherwise git memory usage necessitates using swap space)
  • 2GB is the recommended memory size and supports up to 1,000 users
  • 4GB supports up to 10,000 users

Storage

The necessary hard drive space largely depends on the size of the repos you want to store in GitLab. But as a rule of thumb you should have at least twice as much free space as your all repos combined take up. You need twice the storage because GitLab satellites contain an extra copy of each repo.

If you want to be flexible about growing your hard drive space in the future consider mounting it using LVM so you can add more hard drives when you need them.

Apart from a local hard drive you can also mount a volume that supports the network file system (NFS) protocol. This volume might be located on a file server, a network attached storage (NAS) device, a storage area network (SAN) or on an Amazon Web Services (AWS) Elastic Block Store (EBS) volume.

If you have enough RAM memory and a recent CPU the speed of GitLab is mainly limited by hard drive seek times. Having a fast drive (7200 RPM and up) or a solid state drive (SSD) will improve the responsiveness of GitLab.

Supported Web Browsers

  • Chrome (Latest stable version)
  • Firefox (Latest released version)
  • Safari 7+ (Know problem: required fields in html5 do not work)
  • Opera (Latest released version)
  • IE 10+

Reporting 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.

For ubuntu users I suggest installing docker using docker's own package repository since the version of docker packaged in the ubuntu repositories are a little dated.

Here is the shortform of the installation of an updated version of docker on ubuntu.

sudo apt-get purge docker.io
curl -s https://get.docker.io/ubuntu/ | sudo sh
sudo apt-get update
sudo apt-get install lxc-docker

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.

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

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

  • The host ditribution 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

Pull the latest version of the image from the docker index. This is the recommended method of installation as it is easier to update image in the future. These builds are performed by the Docker Trusted Build service.

docker pull sameersbn/gitlab:latest

Since version 6.3.0, the image builds are being tagged. You can now pull a particular version of gitlab by specifying the version number. For example,

docker pull sameersbn/gitlab:7.2.2

Alternately you can build the image yourself.

git clone https://github.com/sameersbn/docker-gitlab.git
cd docker-gitlab
docker build --tag="$USER/gitlab" .

Quick Start

Run the gitlab image

docker run --name='gitlab' -it --rm \
-e 'GITLAB_PORT=10080' -e 'GITLAB_SSH_PORT=10022' \
-p 10022:22 -p 10080:80 \
-v /var/run/docker.sock:/run/docker.sock \
-v $(which docker):/bin/docker \
sameersbn/gitlab:7.2.2

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

Point your browser to http://localhost:10080 and login using the default username and password:

  • username: root
  • password: 5iveL!fe

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

Configuration

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

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

mkdir -p /opt/gitlab/data
sudo chcon -Rt svirt_sandbox_file_t /opt/gitlab/data

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

docker run --name=gitlab -d \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2

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

MySQL
Internal MySQL Server

Warning

The internal mysql server will soon be removed from the image.

Please use a linked mysql container or specify a connection to a external mysql server.

You've been warned.

If you are already using the internal mysql server then follow these instructions to migrate to a linked mysql container:

Assuming that your mysql data is available at /opt/gitlab/mysql

docker run --name=mysql -d \
  -v /opt/gitlab/mysql:/var/lib/mysql \
  sameersbn/mysql:latest

This will start a mysql container with your existing mysql data. All you need to do now is link this mysql container to the gitlab container using the --link mysql:mysql option.

Refer to Linking to MySQL Container for more information.

This docker image is configured to use a MySQL database backend. The database connection can be configured using environment variables. If not specified, the image will start a mysql server internally and use it. However in this case, the data stored in the mysql database will be lost if the container is stopped/deleted. To avoid this you should mount a volume at /var/lib/mysql.

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

mkdir -p /opt/gitlab/mysql
sudo chcon -Rt svirt_sandbox_file_t /opt/gitlab/mysql

The updated run command looks like this.

docker run --name=gitlab -d \
  -v /opt/gitlab/data:/home/git/data \
  -v /opt/gitlab/mysql:/var/lib/mysql sameersbn/gitlab:7.2.2

This will make sure that the data stored in the database is not lost when the image is stopped and started again.

External MySQL Server

The image can be configured to use an external MySQL database instead of starting a MySQL server internally. 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 SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'%.%.%.%';

To make sure the database is initialized start the container with app:rake gitlab:setup option.

Assuming that the mysql server host is 192.168.1.100

docker run --name=gitlab -it --rm \
  -e 'DB_HOST=192.168.1.100' -e 'DB_NAME=gitlabhq_production' -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2 app:rake gitlab:setup

Append force=yes to the above command to skip the confirmation prompt.

NOTE: The above setup is performed only for the first run.

This will initialize the gitlab database. Now that the database is initialized, start the container normally.

docker run --name=gitlab -d \
  -e 'DB_HOST=192.168.1.100' -e 'DB_NAME=gitlabhq_production' -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2
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_TYPE, 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 sameersbn/mysql image. When using docker-mysql in production you should mount a volume for the mysql data store. Please refer the README of docker-mysql for details.

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

docker pull sameersbn/mysql: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 /opt/mysql/data
sudo chcon -Rt svirt_sandbox_file_t /opt/mysql/data

The updated run command looks like this.

docker run --name=mysql -d \
	-v /opt/mysql/data:/var/lib/mysql \
	sameersbn/mysql:latest

You should now have the mysql server running. By default the sameersbn/mysql image does not assign a password for the root user and allows remote connections for the root user from the 172.17.%.% address space. This means you can login to the mysql server from the host as the root user.

Now, lets login to the mysql server and create a user and database for the GitLab application.

docker run -it --rm sameersbn/mysql:latest mysql -uroot -h$(docker inspect --format {{.NetworkSettings.IPAddress}} mysql)
CREATE USER 'gitlab'@'172.17.%.%' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'172.17.%.%';
FLUSH PRIVILEGES;

Now that we have the database created for gitlab, lets install the database schema. This is done by starting the gitlab container with the app:rake gitlab:setup command.

docker run --name=gitlab -it --rm --link mysql:mysql \
  -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -e 'DB_NAME=gitlabhq_production' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2 app:rake gitlab:setup

NOTE: The above setup is performed only for the first run.

We are now ready to start the GitLab application.

docker run --name=gitlab -d --link mysql:mysql \
  -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -e 'DB_NAME=gitlabhq_production' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2
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;

To make sure the database is initialized start the container with app:rake gitlab:setup option.

Assuming that the PostgreSQL server host is 192.168.1.100

docker run --name=gitlab -it --rm \
  -e 'DB_TYPE=postgres' -e 'DB_HOST=192.168.1.100' -e 'DB_NAME=gitlabhq_production' -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2 app:rake gitlab:setup

NOTE: The above setup is performed only for the first run.

This will initialize the gitlab database. Now that the database is initialized, start the container normally.

docker run --name=gitlab -d \
  -e 'DB_TYPE=postgres' -e 'DB_HOST=192.168.1.100' -e 'DB_NAME=gitlabhq_production' -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2
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_TYPE, 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 sameersbn/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 sameersbn/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 /opt/postgresql/data
sudo chcon -Rt svirt_sandbox_file_t /opt/postgresql/data

The updated run command looks like this.

docker run --name=postgresql -d \
  -v /opt/postgresql/data:/var/lib/postgresql \
  sameersbn/postgresql:latest

You should now have the postgresql server running. The password for the postgres user can be found in the logs of the postgresql image.

docker logs postgresql

Now, lets login to the postgresql server and create a user and database for the GitLab application.

docker run -it --rm sameersbn/postgresql:latest psql -U postgres -h $(docker inspect --format {{.NetworkSettings.IPAddress}} postgresql)
CREATE ROLE gitlab with LOGIN CREATEDB PASSWORD 'password';
CREATE DATABASE gitlabhq_production;
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab;

Now that we have the database created for gitlab, lets install the database schema. This is done by starting the gitlab container with the app:rake gitlab:setup command.

docker run --name=gitlab -it --rm --link postgresql:postgresql \
  -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -e 'DB_NAME=gitlabhq_production' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2 app:rake gitlab:setup

NOTE: The above setup is performed only for the first run.

We are now ready to start the GitLab application.

docker run --name=gitlab -d --link postgresql:postgresql \
  -e 'DB_USER=gitlab' -e 'DB_PASS=password' \
  -e 'DB_NAME=gitlabhq_production' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2

Redis

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

Internal Redis Server

The internal redis server has been removed from the image. Please use a linked redis container or specify a external redis connection.

Notice

The internal mysql server will also be removed in the next release.

If you have been using the internal mysql server, then please migrate to a using a linked mysql server using the migration instructions listed here.

You've been warned

External Redis Server

The image can be configured to use an external redis server instead of starting a redis server internally. 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 \
  -e 'REDIS_HOST=192.168.1.100' -e 'REDIS_PORT=6379' \
  sameersbn/gitlab:7.2.2
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 sameersbn/redis image. Please refer the README of docker-redis for details.

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

docker pull sameersbn/redis:latest

Lets start the redis container

docker run --name=redis -d sameersbn/redis:latest

We are now ready to start the GitLab application.

docker run --name=gitlab -d --link redis:redisio \
  sameersbn/gitlab:7.2.2
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.

The following environment variables need to be specified to get mail support to work.

  • SMTP_ENABLED (defaults to true if SMTP_USER is defined, else defaults to false)
  • SMTP_DOMAIN (defaults to www.gmail.com)
  • SMTP_HOST (defaults to smtp.gmail.com)
  • SMTP_PORT (defaults to 587)
  • SMTP_USER
  • SMTP_PASS
  • SMTP_STARTTLS (defaults to true)
  • SMTP_AUTHENTICATION (defaults to login if SMTP_USER is set)
docker run --name=gitlab -d \
  -e '[email protected]' -e 'SMTP_PASS=PASSWORD' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2
SSL

Access to the gitlab application can be secured using SSL so as to prevent unauthorized access to the data in your repositories. While a CA certified SSL certificate allows for verification of trust via the CA, a self signed certificates can also provide an equal level of trust verification as long as each client takes some additional steps to verify the identity of your website. I will provide instructions on achieving this towards the end of this section.

To secure your application via SSL you basically need two things:

  • Private key (.key)
  • SSL certificate (.crt)

When using CA certified certificates, these files are provided to you by the CA. When using self-signed certificates you need to generate these files yourself. Skip the following section if you are armed with CA certified SSL certificates.

Jump to the Using HTTPS with a load balancer section if you are using a load balancer such as hipache, haproxy or nginx.

Generation of Self Signed Certificates

Generation of self-signed SSL certificates involves a simple 3 step procedure.

STEP 1: Create the server private key

openssl genrsa -out gitlab.key 2048

STEP 2: Create the certificate signing request (CSR)

openssl req -new -key gitlab.key -out gitlab.csr

STEP 3: Sign the certificate using the private key and CSR

openssl x509 -req -days 365 -in gitlab.csr -signkey gitlab.key -out gitlab.crt

Congratulations! you have now generated an SSL certificate thats valid for 365 days.

Strengthening the server security

This section provides you with instructions to strengthen your server security. To achieve this we need to generate stronger DHE parameters.

openssl dhparam -out dhparam.pem 2048
Installation of the SSL Certificates

Out of the four files generated above, we need to install the gitlab.key, gitlab.crt and dhparam.pem files at the gitlab server. The CSR file is not needed, but do make sure you safely backup the file (in case you ever need it again).

The default path that the gitlab application is configured to look for the SSL certificates is at /home/git/data/certs, this can however be changed using the SSL_KEY_PATH, SSL_CERTIFICATE_PATH and SSL_DHPARAM_PATH configuration options.

If you remember from above, the /home/git/data path is the path of the data store, which means that we have to create a folder named certs inside /opt/gitlab/data/ and copy the files into it and as a measure of security we will update the permission on the gitlab.key file to only be readable by the owner.

mkdir -p /opt/gitlab/data/certs
cp gitlab.key /opt/gitlab/data/certs/
cp gitlab.crt /opt/gitlab/data/certs/
cp dhparam.pem /opt/gitlab/data/certs/
chmod 400 /opt/gitlab/data/certs/gitlab.key

Great! we are now just one step away from having our application secured.

Enabling HTTPS support

HTTPS support can be enabled by setting the GITLAB_HTTPS option to true. Additionally, when using self-signed SSL certificates you need to the set SSL_SELF_SIGNED option to true as well. Assuming we are using self-signed certificates

docker run --name=gitlab -d \
  -e 'GITLAB_HTTPS=true' -e 'SSL_SELF_SIGNED=true' \
  -v /opt/gitlab/data:/home/git/data \
  sameersbn/gitlab:7.2.2

In this configuration, any requests made over the plain http protocol will automatically be redirected to use the https protocol. However, this is not optimal when using a load balancer.

Configuring HST

Tag summary

Content type

Image

Digest

sha256:76fa14dc7

Size

254.5 MB

Last updated

almost 11 years ago

docker pull builtdock/docker-gitlab