docker reverse proxy DNS/networking issues

故事扮演 提交于 2019-12-06 01:36:28

Since you didn't post your compose. I am making few assumptions. The compose assumed is below

version: '3'

services:
  nginx:
    image: nginx
    ports:
      - 80:80
      - 443:443
    depends_on:
      - jenkins
      - sonar
  jenkins:
    image: jenkins
  sonar:
    image: sonarqube

And all of these run on 10.10.10.50. Now if you set the DNS to 10.10.10.20 inside and outside, both jenkins.network.com will resolve to 10.10.10.50. But inside the docker network you want jenkins.network.com to resolved to the IP of the container.

So if all above is correct then below is the simplest solution

version: '3'

service:
  nginx:
    image: nginx
    ports:
      - 80:80
      - 443:443
    depends_on:
      - jenkins
      - sonar
  jenkins:
    image: jenkins
    networks:
      default:
        aliases:
          - jenkins.network.com
  sonar:
    image: sonar
    networks:
      default:
        aliases:
          - sonar.network.com

On the nginx image i can reach jenkins.network.com

root@be6492f18851:/# telnet jenkins.network.com 8080
Trying 172.23.0.3...
Connected to jenkins.network.com.
Escape character is '^]'.
Connection closed by foreign host.

And you can do that from both jenkins and sonar containers and get the same results

Edit-1

If you want the DNS to go through proxy, you can change the aliases to that network

version: '3'

service:
  nginx:
    image: nginx
    ports:
      - 80:80
      - 443:443
    depends_on:
      - jenkins
      - sonar
    networks:
      default:
        aliases:
          - sonar.network.com
          - jenkins.network.com
  jenkins:
    image: jenkins
  sonar:
    image: sonar

how about use nginx to do reverse proxy?
if i didn't misunderstand, you want to listen 443 port
and reverse to 172.16.10.1
below is an nginx config example

server {
listen 443;
root /data/up1; 

location / {
  proxy_pass       172.16.10.1;
  proxy_set_header Host      $host;
  proxy_set_header X-Real-IP $remote_addr;
}

hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!