GitLab on Docker with Nginx

Docker provides a way to run applications securely isolated in a container, packaged with all its dependencies and libraries.

Because Docker is developed on Ubuntu, so I finally chose Ubuntu 16.04LTS as my server.

And I found that running GitLab using Docker image is faster than directly running it on server even on 2C4G`s server!

How to install Docker-CE On Ubuntu:
Refer to Docker Official Docs or use one shell script in _NoShell_ repository.

Now, you can search for gitlab-ce docker image on Docker Hub and run the image like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo docker pull gitlab/gitlab-ce
$ sudo docker run --detach \
--hostname your_domain \
--publish 444:443 --publish 81:80 --publish 23: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
$ sudo docker exec -it gitlab /bin/bash
// set external_url=your_domain
gitlat shell >> echo 'external_url=your_domain' >> /etc/gitlab/gitlab.rb

Caution: your_domain will be used in push&pull.

For more about how to run gitlab-ce docker image, you can visit GitLab Official Docs.

Visit your own gitlab on http://localhost or http://your-ip.

With Nginx`s help, you can visit it using your domain name.

Follow these steps below to install latest Nginx on Ubuntu 16.04LTS( Care about the version of Ubuntu ):

1
2
3
4
5
6
7
8
$ wget http://nginx.org/keys/nginx_signing.key
$ sudo apt-get add nginx_signing.key
$ sudo cat >> /etc/apt/source.lists << EOF
deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx
EOF
$ sudo apt-get update
$ sudo apt-get install nginx

After install Nginx successfully, modify the file /etc/nginx/conf.d/default.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo mv /etc/nginx/conf.d/default.conf \
/etc/nginx/conf.d/default.conf.backup
$ sudo cat >> /etc/nginx/conf.d/custom.conf << EOF
upstream gitlab{
server localhost:81;
}
server{
listen 80;
server_name gitlab.domain.com;
location / {
proxy_pass http://gitlab
}
}
EOF

Why the port is 81? Because I expose the Web Interface on port 81 --publish 81:80.

Then restart nginx service:
$ sudo nginx -s reload

Remenber, do not forget open the port you will use.

Finally, you can play with your own gitlab happily!

hsowan wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!