如何将 youtrack、upsource 和 teamcity 连接到同一台机器上的所有 运行 作为 docker 容器

How to connect youtrack, upsource and teamcity to hub all running as docker containers on the same machine

由于我们是一个小团队,我们希望将 JetBrains 的 Hub、Youtrack、Upsource 和 Teamcity 作为 docker 容器(目前都在同一台机器上)。 Docker 在 Photon OS 2.0 运行 上是 运行 在 ESXi 6.7 上。另一个容器中的 Nginx 充当 DNS 代理,因此现在所有服务都可以在端口 80 上使用自己的域名访问...

我获得了所有 5 项服务 运行,并且可以在浏览器中访问它们。然而,将 Youtrack、Upsource 和 Teamcity 连接到 Hub 是一个挑战。 Youtrack、Upsource 和 Teamcity 要求 Hub URL 确认并请求访问 Hub 的权限。


问题:


问题:

  1. 如何 link Youtrack、Upsource 和 Teamcity 到 Hub?为了使确认过程正常工作,docker 容器需要能够使用外部 IP/domain 名称相互访问。
  2. 有什么反对在同一台机器上启动所有四个 Teamtools 并在以后随着需求增长将它们分开的吗?

目前配置:

容器已经变成这样的服务:

/etc/systemd/system/docker.nginx.servcie

[Unit]
Description=Nginx DNS proxy
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=/usr/bin/docker network create --subnet=172.18.0.0/16 dockerNet
ExecStartPre=-/usr/bin/docker exec %n stop
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull jwilder/nginx-proxy
ExecStart=/usr/bin/docker run --rm --name %n \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --net dockerNet --ip 172.18.0.2 \
    -p 80:80 \
    jwilder/nginx-proxy

[Install]
WantedBy=multi-user.target

/etc/systemd/system/docker.hub.service

[Unit]
Description=JetBrains Hub Service
After=docker.nginx-proxy.service
Requires=docker.nginx-proxy.service

[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker exec %n stop
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull jetbrains/hub:2018.2.9635
ExecStart=/usr/bin/docker run --rm --name %n \
    -v /opt/hub/data:/opt/hub/data \
    -v /opt/hub/conf:/opt/hub/conf \
    -v /opt/hub/logs:/opt/hub/logs \
    -v /opt/hub/backups:/opt/hub/backups \
    --net dockerNet --ip 172.18.0.3 \
    -p 8010:8080 \
    --expose 8080 \
    -e VIRTUAL_PORT=8080 \
    -e VIRTUAL_HOST=hub,teamtools.mydomain.com,hub.teamtools.mydomain.com \
    jetbrains/hub:2018.2.9635

[Install]
WantedBy=multi-user.target

...等等。因为我还在尝试,所以端口被映射到主机上并暴露出来,这样 nginx-proxy 就可以获取它们。我还向容器添加了静态 IP,希望这能帮助解决我的问题。

运行 这些服务导致:

CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                    NAMES
7ba8ed89b832        jetbrains/teamcity-server         "/run-services.sh"       12 hours ago        Up 12 hours         0.0.0.0:8111->8111/tcp   docker.teamcity.service
5c819c48cbcc        jetbrains/upsource:2018.1.357     "/bin/bash /run.sh"      12 hours ago        Up 12 hours         0.0.0.0:8030->8080/tcp   docker.upsource.service
cf9dcd1b534c        jetbrains/youtrack:2018.2.42223   "/bin/bash /run.sh"      14 hours ago        Up 14 hours         0.0.0.0:8020->8080/tcp   docker.youtrack.service
de86c3e1f2e2        jetbrains/hub:2018.2.9635         "/bin/bash /run.sh"      14 hours ago        Up 14 hours         0.0.0.0:8010->8080/tcp   docker.hub.service
9df9cb44e485        jwilder/nginx-proxy               "/app/docker-entry..."   14 hours ago        Up 14 hours         0.0.0.0:80->80/tcp       docker.nginx-proxy.service

附加信息:

我确实认为这可能是防火墙问题,这个 post 似乎暗示了同样的事情:

https://forums.docker.com/t/access-docker-container-from-inside-of-the-container-via-external-url/33271

After some discussion with the provider of the virtual server it turned out, that conflicting firewall rules between plesk firewall and iptables caused this problem. After the conflict had been fixed by the provider the container could be accessed.

Photon 上的防火墙,规则由 docker:

自动添加
Chain INPUT (policy DROP 2 packets, 203 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
  258 19408 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    6   360 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
  186 13066 DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0
  186 13066 DOCKER-ISOLATION  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0
  103  7224 ACCEPT     all  --  *      br-83f08846fc2e  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    9   524 DOCKER     all  --  *      br-83f08846fc2e  0.0.0.0/0            0.0.0.0/0
   74  5318 ACCEPT     all  --  br-83f08846fc2e !br-83f08846fc2e  0.0.0.0/0            0.0.0.0/0
    1    52 ACCEPT     all  --  br-83f08846fc2e br-83f08846fc2e  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
  300 78566 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination
    8   472 ACCEPT     tcp  --  !br-83f08846fc2e br-83f08846fc2e  0.0.0.0/0            172.18.0.2           tcp dpt:80
    0     0 ACCEPT     tcp  --  !br-83f08846fc2e br-83f08846fc2e  0.0.0.0/0            172.18.0.3           tcp dpt:8080
    0     0 ACCEPT     tcp  --  !br-83f08846fc2e br-83f08846fc2e  0.0.0.0/0            172.18.0.5           tcp dpt:8080
    0     0 ACCEPT     tcp  --  !br-83f08846fc2e br-83f08846fc2e  0.0.0.0/0            172.18.0.4           tcp dpt:8080
    0     0 ACCEPT     tcp  --  !br-83f08846fc2e br-83f08846fc2e  0.0.0.0/0            172.18.0.6           tcp dpt:8111

Chain DOCKER-ISOLATION (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  br-83f08846fc2e docker0  0.0.0.0/0            0.0.0.0/0
    0     0 DROP       all  --  docker0 br-83f08846fc2e  0.0.0.0/0            0.0.0.0/0
  186 13066 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-USER (1 references)
 pkts bytes target     prot opt in     out     source               destination
  186 13066 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

原来是防火墙问题。

我用这个 https://unrouted.io/2017/08/15/docker-firewall/ 作为起点解决了它。

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:FILTERS - [0:0]
:DOCKER-USER - [0:0]

-F INPUT
-F DOCKER-USER
-F FILTERS

-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp --icmp-type any -j ACCEPT
-A INPUT -j FILTERS

-A DOCKER-USER -i eth0 -j FILTERS

-A FILTERS -m state --state ESTABLISHED,RELATED -j ACCEPT
# full access from my workstation
-A FILTERS -m state --state NEW -s 192.168.0.10/32
-A FILTERS -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A FILTERS -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A FILTERS -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A FILTERS -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FILTERS -j REJECT --reject-with icmp-host-prohibited

COMMIT