Gitlab on Docker
Why
Normally we would not think of hosting a gitlab on local. But we might need one when
- we wish to develop/test our CI-CD pipeline
- try out a new feature
- establish a CI - CD for hobby projects
- establish a CI - CD for hobby projects
Which Gitlab
Gitlab docker images are available in two flavours
- Community Edition
- Enterprise Edition
Enterprise edition needs a license. Without license, it acts as community edition. And as usually is the case - enterprise edition comes with more propriety features.
To switch between which image we wish to use - just change the suffix
- gitlab-ce
- gitlab-ee
Limitation of this approach
- CI / CD is unavailable (For CI/CD refer this)
- Gitlab docker image is a monolith - it contains all the applications it needs in one image. So image is huge - 2.23 GB for me.
Gitlab doesn't work alone for CI-CD. It needs a runner - a helper service. We shall talk about it a little later. If you only use gitlab, you get
- git
- ability to have merge requests
Command
Create a folder: gitlab. And create 3 folders inside gitlab. These will be used to persist gitlab data between container restarts.
docker run --detach \
--hostname localhost:8180 \
--publish 8143:443 --publish 8180:8180 --publish 8122:22 \
--name gitlab \
--restart always \
--volume /Users/hsingh/docker/data/gitlab/config:/etc/gitlab \
--volume /tmp/docker/data/gitlab/logs:/var/log/gitlab \
--volume /Users/hsingh/docker/data/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
Command takes some time to run - gitlab is SLOW.
You can view logs as
docker logs -f gitlab
Note:
- When you see logs starting with a '*', it means gitlab is still starting up. When you start seeing normal logs, it means gitlab has started.
- --hostname : gitlab uses hostname to internally build URLs. It is important.
- The port used inside the container depends on port you gave in --hostname. So make sure that you map the docker inside port to the one you have in --hostname. That is why I mapped 8180:8180 instead of 8180:80 as given in https://docs.gitlab.com/omnibus/docker/ link.
- logs get filled up at a fast pace. So when gitlab stops responding, stop it. Delete all logs. Start it.
- logs getting filled up is the reason I have given /tmp/docker/data/gitlab as logs volume.
I am using CE edititon. To use EE edition, simply change image name to gitlab/gitlab-ee:latest
Navigate gitlab
Open this URL: http://localhost:8180 (or any port you might have exposed). This takes to a page where you are asked to set your admin password.
Now login with username "root" and password what you set in step above.
Now this works as a normal gitlab.
A few things to note
You can clone repo using https. To clone using "git@...", you need to do following
1. Add SSH key to your user in gitlab
2. Make this entry in ~/.ssh/config
Host localhost
Hostname localhost
Port 8122
User root
IdentityFile ~/.ssh/id_rsa
Now clone using "git@" works.
Comments
Post a Comment