Mac M1 基于 Docker 部署 GitLab

2,571 阅读5分钟

Mac M1 基于 Docker 部署 GitLab

1. 前言

哈喽,大家好啊!查阅了 GitLab 安装文档 之后,虽然发现并无关于 M1 芯片版本的介绍,但是发现了 Docker 下的安装,在网上查阅了一些资料之后,决定动手部署下。本文记录下 GitLab 的部署过程。

2. 前置条件

因为安装基于 Docker ,那么请提前下载 Docker Desktop for Mac with Apple silicon 并安装 ,具体的安装过程比较简单明了,这里暂时按下不表。另外仅仅需要 一点点 Docker 前置知识。

3. 安装

3.1 查询镜像

使用 docker search gitlab-ce 查询下镜像。

➜  ~ docker search gitlab-ce
NAME                                     DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
drud/gitlab-ce                                                                            15
rapidfort/gitlab-ce                                                                       2
gitlab/gitlab-ce                         GitLab Community Edition docker image based …   3885                 [OK]
slpcat/gitlab-ce                         gitlab-ce最新社区版10.1.0,omnibus二进制包       3
imachineml/gitlab-ce                                                                      0
yrzr/gitlab-ce-arm64v8                   GitLab Community Edition docker image for ar…   67
gitlab/gitlab-ce-qa                      GitLab QA has a test suite that allows end-t…   9
polinux/gitlab-ce                        GitLab-CE on Steroids (Extra features - see …   3                    [OK]
twang2218/gitlab-ce-zh                   汉化的 GitLab 社区版 Docker Image                267                  [OK]
beginor/gitlab-ce                        GitLab Community Edition with zh-cn              74                   [OK]
visualon/gitlab-ce                       customized gitlab-ce docker image                0
marq/gitlab-ce-subgit                    A GitLab container with SubGit included.         3                    [OK]
jbuncle/gitlab-ce                                                                         0
lezapedrola/gitlab-ce                                                                     0
oidatiftla/gitlab-ce                     Mirror of gitlab/gitlab-ce with more tags (m…   0
toshi0123/gitlab-ce                      gitlab-ce based on alpine linux                  0                    [OK]
visitsb/gitlab-ce                        Fixes official https://hub.docker.com/r/gitl…   0
sstruss/gitlab-ce-armhf                  gitlab-ce armhf image for armv7/armhf platfo…   0
idoall/gitlab-ce                         gitlab-ce                                        1                    [OK]
projectatomic/gitlab-centos7-atomicapp   Gitlab Atomic App                                1                    [OK]
computersciencehouse/gitlab-ce-oidc      GitLab CE Docker image with OpenID Connect s…   1                    [OK]
chefplatform/gitlab-ce-kitchen           Docker image based on gitlab/gitlab-ce provi…   0
lizhenliang/gitlab-ce-zh                                                                  2
ragboy/gitlab-ce                         gitlab-ce 8.4.2                                  0
wlsf82/gitlab-ce                         Fork of GitLab Community Edition docker imag…   0

3.2 获取镜像

选择 ARM 64 版本拉取,即 docker pull yrzr/gitlab-ce-arm64v8 如果大家赶时间的话,建议选择国内的安装源,不然会有那么亿点点久。。docker images 查看下下载情况。

➜  ~ docker pull yrzr/gitlab-ce-arm64v8
Using default tag: latest
latest: Pulling from yrzr/gitlab-ce-arm64v8
a774dfcdedc7: Pull complete
e5cd4d500502: Pull complete
a89e40d5921e: Pull complete
973e11690cfa: Pull complete
c71dd370f322: Pull complete
cf2005072a9c: Pull complete
d436456d102d: Pull complete
354a7b6d3112: Pull complete
Digest: sha256:30d2a72c37de4d244fc044507d748b5a4ea114ac873a93ba092665aeb858bb4e
Status: Downloaded newer image for yrzr/gitlab-ce-arm64v8:latest
docker.io/yrzr/gitlab-ce-arm64v8:latest

➜  ~ docker images
REPOSITORY               TAG       IMAGE ID       CREATED       SIZE
yrzr/gitlab-ce-arm64v8   latest    83ca55befda4   5 weeks ago   2.86GB

3.2 启动

下面执行 docker run 命令,执行前准备好对应的文件夹进行映射。

docker run \
  -itd \
	--name gitlab \
	--privileged \
  --restart always \
  -p 9022:22 \
  -p 9080:80 \
  -v /Users/username/docker/gitlab/etc:/etc/gitlab \
  -v /Users/username/docker/gitlab/log:/var/log/gitlab \
  -v /Users/username/docker/gitlab/opt:/var/opt/gitlab \
  yrzr/gitlab-ce-arm64v8:latest

以下是从 docker run 指引 上截取的部分参数描述:

Name, shorthandDefaultDescription
--detach , -dRun container in background and print container ID
--interactive , -iKeep STDIN open even if not attached
--memory , -mMemory limit
--nameAssign a name to the container
--privilegedGive extended privileges to this container
--publish , -pPublish a container’s port(s) to the host
--restartnoRestart policy to apply when a container exits
--tty , -tAllocate a pseudo-TTY
--volume , -vBind mount a volume

启动成功!

➜  ~ docker run \
  -itd \
        --name gitlab \
        --privileged \
  --restart always \
  -p 9022:22 \
  -p 9080:80 \
  -v /Users/username/docker/gitlab/etc:/etc/gitlab \
  -v /Users/username/docker/gitlab/log:/var/log/gitlab \
  -v /Users/username/docker/gitlab/opt:/var/opt/gitlab \
  yrzr/gitlab-ce-arm64v8:latest
ab5d2f6478a3d0d43cf9bc31d9b0bbb335093ca7ef4cd82f1ab6ffc15db56736

访问 IP:9080 看到如下页面就成功啦!右下角可以切换为中文,相当 nice!

Untitled.png

4. 登录

4.1 登录失败

所以。。怎么登录呢?没有账号密码啊。没关系,先注册一个。。注册完成之后,就可以登录了。

Untitled 1.png

居然行不通。。好吧,这其实是个玩笑。

Untitled 2.png

4.2 获取密码

不慌,进入容器看看先。执行 docker container ls 再执行下 docker exec -it ab5d2f6478a3 /bin/bash

➜  ~ docker container ls
CONTAINER ID   IMAGE                           COMMAND             CREATED          STATUS                    PORTS                                                 NAMES
ab5d2f6478a3   yrzr/gitlab-ce-arm64v8:latest   "/assets/wrapper"   32 minutes ago   Up 32 minutes (healthy)   443/tcp, 0.0.0.0:9022->22/tcp, 0.0.0.0:9080->80/tcp   gitlab
➜  ~ docker exec -it ab5d2f6478a3 /bin/bash
root@ab5d2f6478a3:/#

进入容器后切换至 GitLab 安装文件夹,执行 cd /etc/gitlab && ls -l

root@ab5d2f6478a3:/# cd /etc/gitlab && ls -l
total 192
-rw------- 1 root root  19408 May 11 07:29 gitlab-secrets.json
-rw------- 1 root root 144403 May 11 07:29 gitlab.rb
-rw------- 1 root root    749 May 11 07:29 initial_root_password
-rw------- 1 root root    513 May 11 07:29 ssh_host_ecdsa_key
-rw-r--r-- 1 root root    179 May 11 07:29 ssh_host_ecdsa_key.pub
-rw------- 1 root root    411 May 11 07:29 ssh_host_ed25519_key
-rw-r--r-- 1 root root     99 May 11 07:29 ssh_host_ed25519_key.pub
-rw------- 1 root root   2602 May 11 07:29 ssh_host_rsa_key
-rw-r--r-- 1 root root    571 May 11 07:29 ssh_host_rsa_key.pub
drwxr-xr-x 2 root root     64 May 11 07:29 trusted-certs

发现有个 initial_root_password 文件,啊哈。。里面就是 root 账号的密码。24 小时之后会被删除!

root@ab5d2f6478a3:/etc/gitlab# cat initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: ~~LDSWswARSCl7O9v4NjyXJQR7u+p9RVvDv6H+YUjDmgw=~~

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

4.3 成功登录

输入账号密码之后,终于看到了梦寐以求的页面。。记得修改下密码,再登录哦。

Untitled 3.png

5. 结语

至此,就安装成功了!然后就是咱们的老传统进行应用啦。未完待续,接下来:

参考文档

docs.docker.com/

docs.docker.com/engine/refe…

docs.gitlab.com/runner/inst…