Deploy GitLab Through Docker

Deploying Gitlab through docker has become a lot simpler than it used to be.

Requirements

  • 512 MB With 1.5 GB of Swap or 2GB RAM (better)

Steps

If you haven't already, install docker, then install docker compose.

Next, we need to change the server's SSH port from the default 22 to something else such as 2222 or 23825. You can do this by
editing the /etc/ssh/sshd_config file and changing the line below

...
# What ports, IPs and protocols we listen for 
Port 22
...

You will need to remember this so that next time you SSH into the server, you specify the port with -p like so:

ssh -p 2222 my-host-or-ip.org

Now we can deploy the gitlab container by executing the following script:

HOSTNAME="gitlab.mydomain.com"

sudo docker run --detach \
    --hostname $HOSTNAME \
    --publish 443:443 --publish 80:80 --publish 22:22 \
    --name gitlab \
    --restart always \
    --volume $PWD/gitlab/config:/etc/gitlab \
    --volume $PWD/gitlab/logs:/var/log/gitlab \
    --volume $PWD/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

Don't forget to set the HOSTNAME.

After the container has deployed, you will need to wait a while before the website will appear when you type your server's IP or hostname into your browser's URL.

Updating Gitlab

Run the following commands to update to the latest version of Gitlab. However, I recommend taking a snapshot of your server first just in case.

# Pull the latest image
docker pull gitlab/gitlab-ce:latest

# kill and remove the existing container
docker kill `gitlab`
docker rm `gitlab`

# Launch a new container using the new image.
sudo docker run --detach \
    --hostname gitlab.example.com \
    --publish 443:443 --publish 80:80 --publish 22:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

Outdated Method

Everything below this line is the original instructions that used to be on this page and are kept for reference. If you are deploying a new Gitlab server, please do not use these instructions.

Requirements

You will require a server with a significant amount of memory. I gave my virtualbox instance 1500 MB and immediately after starting the application, with nothing else running on the server, I am using 1088 MB.

Install

If you haven't already, install docker, then install docker compose.

Copy/paste the script below into a file before executing it once in order to set everything up and get you going:

#!/bin/bash

# Ask the user for all necessary details
echo "Please enter the hostname or public IP of this"
echo "server. This will be used in the generation"
echo "of email links to register user accounts."
read HOSTNAME

echo ""
echo "Please enter the email address that should "
echo "get admin email notifications:"
read ADMIN_EMAIL

echo ""
echo "Enter the Google email address gitlab should "
echo "use to send emails: "
read SMTP_EMAIL_ADDRESS

echo ""
echo "To use a gmail account, applications need "
echo "an app-specific password. You can generate "
echo "them here: http://bit.ly/1SYGVMi"
echo ""
echo "Please enter the app-specific password for"
echo "the email account that will send emails:"
read EMAIL_PASSWORD


# Install
docker pull sameersbn/gitlab:8.4.4
wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
export GITLAB_SECRETS_DB_KEY_BASE=`openssl rand -base64 32`
echo "export GITLAB_SECRETS_DB_KEY_BASE=`echo $GITLAB_SECRETS_DB_KEY_BASE`" > gitlab_secret_db_key.txt

# Configure the compose file with
# email configuration details
# from what we asked the user
FILEPATH="docker-compose.yml"

SEARCH="    - GITLAB_EMAIL=notifications@example.com"
REPLACE="    - GITLAB_EMAIL=`echo $ADMIN_EMAIL`"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

SEARCH="    - SMTP_USER=mailer@example.com"
REPLACE="    - SMTP_USER=`echo $SMTP_EMAIL_ADDRESS`"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

SEARCH="    - SMTP_PASS=password"
REPLACE="    - SMTP_PASS=`echo $EMAIL_PASSWORD`"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

SEARCH="    - SMTP_ENABLED=false"
REPLACE="    - SMTP_ENABLED=true"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

SEARCH="    - GITLAB_HOST=localhost"
REPLACE="    - GITLAB_HOST=`echo $HOSTNAME`"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH


# Deploy all the things!
docker-compose up

Then navigate to: http://[Server IP or hostnme]:10080 and login with:

  • username: root
  • password: 5iveL!fe

All your data is stored in volume folders within /srv/docker/gitlab/ so it will persist across reboots and destroyed containers.

If you ever lose your containers, you can run run the following script to start GitLab up again:

source gitlab_secret_db_key.txt
docker-compose up

Your done! I hope you found this extremely simple.

References

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus