问题描述
- 使用docker部署gitlab
- 配置好SMTP发送邮件通知
- 新建账号时,发送邮件通知
- 但是在点击邮件内的URL时,URL地址不正确导致无法打开连接
错误的配置过程
- 启动容器
- 最初我是将宿主机10080映射到容器的80端口
- 使用的汉化版本镜像 twang2218/gitlab-ce-zh:latest
docker run \
-d \
-h 192.168.170.101 \
-p 10443:443 -p 10080:80 -p 10022:22 \
--name gitlab \
--restart always \
-v /srv/gitlab/config:/etc/gitlab \
-v /srv/gitlab/logs:/var/log/gitlab \
-v /srv/gitlab/data:/var/opt/gitlab \
twang2218/gitlab-ce-zh:latest
- 配置SMTP发送邮件
- 最初我并没有配置external_url
# external_url
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '你的QQ邮箱'
gitlab_rails['gitlab_email_display_name'] = '陈洋'
gitlab_rails['gitlab_email_reply_to'] = '你的QQ邮箱'
gitlab_rails['gitlab_email_subject_suffix'] = ''
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "你的QQ邮箱"
gitlab_rails['smtp_password'] = "此处填授权码"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
试错
external_url 'http://192.168.170.101:10080'
问题分析
- 将宿主机10080映射到容器的80端口
- 未配置external_url时,WEB访问没问题,只是邮件地址不对
- 修改external_url后,重启容器却直接无法访问web
- 分析启动容器时的映射,最终发现是端口映射的问题
- 启动容器时宿主机的web端口最好和容器的web端口一致
正确的配置过程
docker run \
-d \
-h 192.168.170.101 \
-p 10443:443 -p 10080:10080 -p 10022:22 \
--name gitlab \
--restart always \
-v /srv/gitlab/config:/etc/gitlab \
-v /srv/gitlab/logs:/var/log/gitlab \
-v /srv/gitlab/data:/var/opt/gitlab \
twang2218/gitlab-ce-zh:latest
external_url 'http://192.168.170.101:10080'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '你的QQ邮箱'
gitlab_rails['gitlab_email_display_name'] = '陈洋'
gitlab_rails['gitlab_email_reply_to'] = '你的QQ邮箱'
gitlab_rails['gitlab_email_subject_suffix'] = ''
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "你的QQ邮箱"
gitlab_rails['smtp_password'] = "此处填授权码"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
- 再测试,完美解决