Fork of sameersbn/docker-gitlab, inheriting from Debian and using only official Images.
329
Dockerfile to build a GitLab container image. This is a fork of sameersbn/docker-gitlab with the following modifications:
Current Version: 7.10.4
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.
If you find this image useful here's how you can help:
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:
docker version commanddocker info commanddocker run command you used to run the image (mask out the sensitive bits).Pull the image from the docker index. This is the recommended method of installation as it is easier to update image. These builds are performed by the Docker Trusted Build service.
docker pull sebastiangraf/gitlab:7.10.4
You can also pull the latest tag which is built from the repository HEAD
docker pull sebastiangraf/gitlab:latest
Alternately you can build the image locally.
git clone https://github.com/sebastiangraf/docker-gitlab.git
cd docker-gitlab
docker build --tag="$USER/gitlab" .
Follow this simple 3 step procedure to get started.
Step 1. Launch a postgresql container
docker run --name=postgres -d \
--volume=/srv/docker/gitlab/postgresql:/var/lib/postgresql \
postgres:9.1
Step 2. Launch a redis container
docker run --name=redis -d redis:latest
Step 3. Launch the gitlab container
docker run --name='gitlab' -d \
--link=postgres:postgresql --link=redis:redisio \
--env='DB_USER=postgres' --env='GITLAB_PORT=10080' \
--env='GITLAB_SSH_PORT=10022' --publish=10022:22 \
--publish=10080:80 --volume=/srv/docker/gitlab/gitlab:/home/git/data
sebastiangraf/gitlab:7.10.4
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:
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.
The above setup can also be achieved using docker-compose. Assuming you have docker-compose installed,
wget https://raw.githubusercontent.com/sebastiangraf/docker-gitlab/master/docker-compose.yml
docker-compose up
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.
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/dataSELinux 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 \
sebastiangraf/gitlab:7.10.4
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. The Mysql-section was thereby removed from this fork.
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;
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_TYPE=postgres' --env='DB_HOST=192.168.1.100' \
--env='DB_NAME=gitlabhq_production' \
--env='DB_USER=postgres' \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
sebastiangraf/gitlab:7.10.4
If you set any password in the external image, you have to set it as a variable via "DB_PASSWORD".
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 official postgres image image. When using postgresql image in production you should mount a volume for the postgresql data store.
First, lets pull the postgresql image from the docker index.
docker pull postgres:9.1
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=postgres -d \
--volume=/srv/docker/gitlab/postgresql:/var/lib/postgresql \
postgres:9.1
The above command will create a standard database. Gitlab creates its database named gitlabhq_production with the user named postgres and no password.
We are now ready to start the GitLab application.
docker run --name='gitlab' -d --link=postgres:postgresql --env='DB_USER=postgres' \ --volume=/srv/docker/gitlab/gitlab:/home/git/data sebastiangraf/gitlab:7.10.4
GitLab uses the redis server for its key-value data store. The redis server connection details can be specified using environment variables.
The internal redis server has been removed from the image. Please use a linked redis container or specify a external redis connection.
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' \
--volume=/srv/docker/gitlab/redis:/var/lib/redis \
sebastiangraf/gitlab:7.10.4
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 offical redis image image. Please refer the README of docker-redis for details.
First, lets pull the redis image from the docker index.
docker pull redis:latest
Lets start the redis container
docker run --name=redis -d redis:latest
We are now ready to start the GitLab application.
docker run --name=gitlab -d --link=redis:redisio \
sebastiangraf/gitlab:7.10.4
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.
Please refer the Available Configuration Parameters section for the list of SMTP parameters that can be specified.
docker run --name=gitlab -d \
--env='[email protected]' --env='SMTP_PASS=PASSWORD' \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
sebastiangraf/gitlab:7.10.4
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:
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 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.
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
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 /srv/docker/gitlab/gitlab/ 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 /srv/docker/gitlab/gitlab/certs
cp gitlab.key /srv/docker/gitlab/gitlab/certs/
cp gitlab.crt /srv/docker/gitlab/gitlab/certs/
cp dhparam.pem /srv/docker/gitlab/gitlab/certs/
chmod 400 /srv/docker/gitlab/gitlab/certs/gitlab.key
Great! we are now just one step away from having our application secured.
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 \
--env='GITLAB_HTTPS=true' --env='SSL_SELF_SIGNED=true' \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
sebastiangraf/gitlab:7.10.4
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.
HSTS if supported by the browsers makes sure that your users will only reach your sever via HTTPS. When the user comes for the first time it sees a header from the server which states for how long from now this site should only be reachable via HTTPS - that's the HSTS max-age value.
With GITLAB_HTTPS_HSTS_MAXAGE you can configure that value. The default value is 31536000 seconds. If you want to disable a already sent HSTS MAXAGE value, set it to 0.
docker run --name=gitlab -d \
--env='GITLAB_HTTPS=true' --env='SSL_SELF_SIGNED=true' \
--env='GITLAB_HTTPS_HSTS_MAXAGE=2592000'
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
sebastiangraf/gitlab:7.10.4
If you want to completely disable HSTS set GITLAB_HTTPS_HSTS_ENABLED to false.
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. Additionally you will need to set the SSL_SELF_SIGNED option to true if self signed SSL certificates are in use.
With this in place, you should configure the load balancer to support handling of https requests. But that is out of the scope of this document. Please refer to Using SSL/HTTPS with HAProxy for information on the subject.
When using a load balancer, you probably want to make sure the load balancer performs the automatic http to https redirection. Information on this can also be found in the link above.
In summation, when using a load balancer, the docker command would look for the most part something like this:
docker run --name=gitlab -d \
--publish=10022:22 --publish=10080:80 \
--env='GITLAB_SSH_PORT=10022' --env='GITLAB_PORT=443' \
--env='GITLAB_HTTPS=true' --env='SSL_SELF_SIGNED=true' \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
sebastiangraf/gitlab:7.10.4
Again, drop the --env='SSL_SELF_SIGNED=true' option if you are using CA certified SSL certificates.
In case Gitlab responds to any kind of POST request (login, OAUTH, changing settings etc.) with a 422 HTTP Error, consider adding this to your reverse proxy configuration:
proxy_set_header X-Forwarded-Ssl on; (nginx format)
This section deals will self-signed ssl certificates. If you are using CA certified certificates, your done.
This section is more of a client side configuration so as to add a level of confidence at the client to be 100 percent sure they are communicating with whom they think they.
This is simply done by adding the servers certificate into their list of trusted certificates. On ubuntu, this is done by copying the gitlab.crt file to /usr/local/share/ca-certificates/ and executing update-ca-certificates.
Again, this is a client side configuration which means that everyone who is going to communicate with the server should perform this configuration on their machine. In short, distribute the gitlab.crt file among your developers and ask them to add it to their list of trusted ssl certificates. Failure to do so will result in errors that look like this:
git clone https://git.local.host/gitlab-ce.git
fatal: unable to access 'https://git.local.host/gitlab-ce.git': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
You can do the same at the web browser. Instructions for installing the root certificate for firefox can be found here. You will find similar options chrome, just make sure you install the certificate under the authorities tab of the certificate manager dialog.
There you have it, thats all there is to it.
If your GitLab CI server is using self-signed SSL certificates then you should make sure the GitLab CI server certificate is trusted on the GitLab server for them to be able to talk to each other.
The default path image is configured to look for the trusted SSL certificates is at /home/git/data/certs/ca.crt, this can however be changed using the CA_CERTIFICATES_PATH configuration option.
Copy the ca.crt file into the certs directory on the datastore. The ca.crt file should contain the root certificates of all the servers you want to trust. With respect to GitLab CI, this will be the contents of the gitlab_ci.crt file as described in the README of the docker-gitlab-ci container.
By default, our own server certificate gitlab.crt is added to the trusted certificates list.
By default GitLab expects that your application is running at the root (eg. /). This section explains how to run your application inside a directory.
Let's assume we want to deploy our application to '/git'. GitLab needs to know this directory to generate the appropriate routes. This can be specified using the GITLAB_RELATIVE_URL_ROOT configuration option like so:
docker run --name=gitlab -it --rm \
--env='GITLAB_RELATIVE_URL_ROOT=/git' \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
sebastiangraf/gitlab:7.10.4
GitLab will now be accessible at the /git path, e.g. http://www.example.com/git.
Note: The GITLAB_RELATIVE_URL_ROOT parameter should always begin with a slash and SHOULD NOT have any trailing slashes.
docker run --name=gitlab -d -h git.local.host \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
--volume=/srv/docker/gitlab/postgresql:/var/lib/postgresql \
--env='GITLAB_HOST=git.local.host' --env='[email protected]' \
--env='[email protected]' --env='SMTP_PASS=PASSWORD' \
sebastiangraf/gitlab:7.10.4
If you are using an external database
docker run --name=gitlab -d -h git.local.host \
--volume=/srv/docker/gitlab/gitlab:/home/git/data \
--env='DB_HOST=192.168.1.100' --env='DB_NAME=gitlabhq_production' \
--env='DB_USER=gitlab' --env='DB_PASS=password' \
--env='GITLAB_HOST=git.local.host' --env='GITLAB_EMAIL
Content type
Image
Digest
sha256:fb2a3dbff…
Size
240.7 MB
Last updated
over 11 years ago
docker pull sebastiangraf/docker-gitlab