docker pull gitlab/gitlab-ce
2、启动并访问
docker run -d -p 4430:443 -p 8000:80 -p 220:22 --name gitlab -v /opt/gitlab/config:/etc/gitlab -v /opt/gitlab/logs:/var/log/gitlab -v /opt/gitlab/data:/var/opt/gitlab -v /etc/localtime:/etc/localtime gitlab/gitlab-ce
3、寻找初始化密码
// 寻找初始化密码 root@9612675b29c8:/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: rdJvqhblr/mVRX7x4LGtTJEXjK43Z4k55cCGYyTNc7w= # NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
4、修改初始化密码
修改初始化密码 root@9612675b29c8:/etc/gitlab# gitlab-rails console -------------------------------------------------------------------------------- Ruby: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux] GitLab: 14.10.2 (07d12f3fd11) FOSS GitLab Shell: 13.25.1 PostgreSQL: 12.7 ------------------------------------------------------------[ booted in 68.71s ] Loading production environment (Rails 6.1.4.7) irb(main):001:0> user = User.where(id: 1).first => #irb(main):003:0> user.password=12345678 => 12345678 irb(main):004:0> user.password_confirmation=12345678 => 12345678 irb(main):006:0> user.save! => true irb(main):007:0> quit
5、再次配置gitlab
# 192.168.163.137 为docker宿主机地址 # 编辑gitlab.rb文件,修改以下几个配置的值: vi /opt/gitlab/config/gitlab.rb # 配置http协议所使用的访问地址,端口为上述docker run中配置的端口800 external_url 'http://192.168.163.137:8000' # 配置ssh协议所使用的访问地址和端口(端口为上述docker run中配置的端口220) gitlab_rails['gitlab_ssh_host'] = '192.168.163.137' gitlab_rails['gitlab_shell_ssh_port'] = 220 # 此端口是run时22端口映射的220端口
改完配置需要重启, 重启gitlab
docker restart gitlab
此时访问http://ip:8000无法访问,防火墙也已经打开8000端口。发现是由于改了external_url 'http://192.168.163.137:8000’的端口为8000后,gitlab容器的内部端口也被改为了8000,
而我们在运行gitlab的时候,映射的是8000:80端口,故此时需要先stop容器、rm容器,然后重新以8000:8000的映射方式运行。
-- gitlab重新启动,指定8000:8000, config指向目录不发生变化 docker run -d -p 4430:443 -p 8000:8000 -p 220:22 --name gitlab -v /opt/gitlab/config:/etc/gitlab -v /opt/gitlab/logs:/var/log/gitlab -v /opt/gitlab/data:/var/opt/gitlab -v /etc/localtime:/etc/localtime gitlab/gitlab-ce
6、访问
此时http://192.168.163.137:8000能正常访问,且配置正确。
http://192.168.163.137:8000
二、安装gitlab-runner 1、docker安装
docker pull gitlab/gitlab-runner
2、启动gitlab-runner
docker run -d --name gitlab-runner --restart always -v /opt/gitlab-runner/config:/etc/gitlab-runner -v /opt/gitlab-runner/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
日志抱错误信息, 但是不要担心
ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0 ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0 ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0 ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0 ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0 ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0 ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0
3、配置gitlab-runner
[root@localhost config]# docker exec -it gitlab-runner /bin/bash root@52902f4a8686:/# gitlab-runner register Runtime platform arch=amd64 os=linux pid=22 revision=f761588f version=14.10.1 Running in system-mode. Enter the GitLab instance URL (for example, https://gitlab.com/): http://192.168.163.137:8000/ Enter the registration token: GR1348941GipjG3XE3oT72TKrKBZ6 Enter a description for the runner: [52902f4a8686]: test-runner Enter tags for the runner (comma-separated): test Enter optional maintenance note for the runner: test-runner Registering runner... succeeded runner=GR1348941GipjG3XE Enter an executor: custom, parallels, virtualbox, kubernetes, docker, docker-ssh, shell, ssh, docker+machine, docker-ssh+machine: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
4、配置gitlab-ci文件
5、运行结果
三、错误信息
Running with gitlab-runner 14.10.1 (f761588f) on test-runner WZyG1HdA Preparing the "shell" executor 00:00 Using Shell executor... Preparing environment 00:00 Running on 52902f4a8686... Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Initialized empty Git repository in /home/gitlab-runner/builds/WZyG1HdA/0/test/helloworld/.git/ Created fresh repository. fatal: unable to access 'http://9612675b29c8/test/helloworld.git/': Could not resolve host: 9612675b29c8 ERROR: Job failed: exit status 1
错误: fatal: unable to access 'http://9612675b29c8/test/helloworld.git/': Could not resolve host: 9612675b29c8
9612675b29c8 为gitlab server的镜像id, gitlab-runner以为那就是gitlab的主机地址
请参考: 第一节 -> 再次配置gitlab



