使用Docker构建GitLab
环境( )
OS – softwareversionMacMojave 10.14Docker18.06.1-cedocker-compose1.22.0GitLabCommunity Edition 11.4.0
获取docker-compose.yml文件
由于存在一个能够启动GitLab容器的docker-compose.yml文件,因此可以在GitHub上获取。
$ mydir=myGitlab; cd && mkdir -p ${mydir} && cd ${mydir}
$ wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
使用docker-compose up -d进行启动。
在与docker-compose.yml文件相同的目录中执行。
$ docker-compose up -d
Creating network "docker-gitlab_default" with the default driver
Pulling redis (sameersbn/redis:4.0.9-1)...
4.0.9-1: Pulling from sameersbn/redis
6b98dfc16071: Pull complete
:
:
:
Status: Downloaded newer image for sameersbn/gitlab:11.4.0
Creating docker-gitlab_redis_1 ... error
Creating docker-gitlab_postgresql_1 ...
ERROR: for docker-gitlab_redis_1 Cannot start service redis: b'Mounts denied: \r\nThe path /srv/docker/gitlab/redis\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared pathCreating docker-gitlab_postgresql_1 ... error
ERROR: for docker-gitlab_postgresql_1 Cannot start service postgresql: b'Mounts denied: \r\nThe path /srv/docker/gitlab/postgresql\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'
ERROR: for redis Cannot start service redis: b'Mounts denied: \r\nThe path /srv/docker/gitlab/redis\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'
ERROR: for postgresql Cannot start service postgresql: b'Mounts denied: \r\nThe path /srv/docker/gitlab/postgresql\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'
ERROR: Encountered errors while bringing up the project.
发生错误。
– 原因:docker-compose.yml中volumes选项指向了无法共享的路径。
– 解决方法:将volumes选项的主机路径更改为可共享的区域。
解决错误
$ # 差分確認用でバックアップ作成
$ cp docker-compose.yml docker-compose.yml.org
$ # sedで置換
$ sed -i -e 's/\/srv\/docker\/gitlab/\.\/srv\/docker\/gitlab/g' docker-compose.yml
$ # 差分確認
$ diff docker-compose.yml docker-compose.yml.org
--- docker-compose.yml 2018-10-29 17:14:00.000000000 +0900
+++ docker-compose.yml.org 2018-10-29 17:09:00.000000000 +0900
@@ -9,3 +9,3 @@
volumes:
- - ./srv/docker/gitlab/redis:/var/lib/redis:Z
+ - /srv/docker/gitlab/redis:/var/lib/redis:Z
@@ -15,3 +15,3 @@
volumes:
- - ./srv/docker/gitlab/postgresql:/var/lib/postgresql:Z
+ - /srv/docker/gitlab/postgresql:/var/lib/postgresql:Z
environment:
@@ -32,3 +32,3 @@
volumes:
- - ./srv/docker/gitlab/gitlab:/home/git/data:Z
+ - /srv/docker/gitlab/gitlab:/home/git/data:Z
environment:
如果/srv变为./srv,那就没问题了。
再度 docker-compose up -d を実行
$ docker-compose up -d
Creating network "mygitlab_default" with the default driver
Creating mygitlab_redis_1 ... done
Creating mygitlab_postgresql_1 ... done
Creating mygitlab_gitlab_1 ... done
全てdoneになれば、OK。
更改 GitLab 的 root 用户密码。
-
- 1) ブラウザでhttp://localhost:10080にアクセス。
- 2) rootユーザーのパスワードを変更する画面が出てくるので、変更。
以root用户(管理员)身份登录
-
- Username or emailの入力欄 : root
Passwordの入力欄 : 変更したパスワード
如果见到GitLab的界面,请确认一下。