Answers: <p>You can use a proxy to forward traffic between the two services, I typically do something like this which includes automated SSL with certbot. In the example below I have two services listening on port 80/443 (Sonarqube and Jenkins). You can also see I can reference container hosts by name (https://jenkins:8080)</p>
  <pre><code>nginx:
  container_name: nginx-certbot
  restart: unless-stopped
  image: staticfloat/nginx-certbot
  networks:
    - local
  ports:
    - &quot;0.0.0.0:80:80&quot;
    - &quot;0.0.0.0:443:443&quot;
  environment:
    CERTBOT_EMAIL: &lt;insert_email&gt;
  volumes:
    - ./conf.d:/etc/nginx/user.conf.d:ro
    - letsencrypt:/etc/letsencrypt
  </code></pre>
  <p>And this is what my nginx config looks like</p>
  <pre><code>server {
  listen              443 ssl;
  server_name jenkins.hauntedmansion.io;
  ssl_certificate     /etc/letsencrypt/live/jenkins.hauntedmansion.io/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/jenkins.hauntedmansion.io/privkey.pem;
  
  client_max_body_size 20M;
  
    location / {
      proxy_set_header   Host $host;
      proxy_set_header   X-Real-IP $remote_addr;
      proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_pass         http://jenkins:8080;
      proxy_read_timeout 90;
      proxy_redirect     http://127.0.0.1:8080 https://jenkins.hauntedmansion.io;
    }
  }
  </code></pre>
  <p>If you want to see the full docker compose example check it out here:</p>
  <p><a href="https://gist.github.com/cvega/66e0e5a2815e9b923da2c616f74dea7e" rel="nofollow noreferrer">https://gist.github.com/cvega/66e0e5a2815e9b923da2c616f74dea7e</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-16T16:26:19.543Z
Answers: 2020-09-16T16:26:19.543Z
Answers: casey vega
Body: <p>I have a docker file that runs some integration tests between two containers. It looks a bit like this:</p>
  <pre><code>version: '3'
  services:
      test_client:
          image: client:latest
          depends_on:
            - test_server
          command: bash -c &quot;run_test.sh -p 80&quot;
      test_server:
          image: server:latest
  </code></pre>
  <p><code>test_server</code> launches a web server on port 80, but that same port is already exposed within <code>test_client</code> (I don't have control over the part of the <code>client:latest</code> image where the port is exposed. I tried using the <code>port: 8080:80</code> to forward port 80 to 8080 in the server, but that only changes the port exposed on the host, not within the docker environment.</p>
  <p>How can I connect <code>test_client</code> to <code>test_server</code> in such a scenario?</p>
  
Tags: <docker><networking>
Title: How can I access port 80 of another container, when port 80 is already exposed?
UserDisplayName: quant
ThreadText: # How can I access port 80 of another container, when port 80 is already exposed?
  
  (Asked by: username_0 on 2020-09-16)
  
  I have a docker file that runs some integration tests between two containers. It looks a bit like this:
  
  ```
  version: '3'
  services:
      test_client:
          image: client:latest
          depends_on:
            - test_server
          command: bash -c "run_test.sh -p 80"
      test_server:
          image: server:latest
  
  ```
  
  `test_server` launches a web server on port 80, but that same port is already exposed within `test_client` (I don't have control over the part of the `client:latest` image where the port is exposed. I tried using the `port: 8080:80` to forward port 80 to 8080 in the server, but that only changes the port exposed on the host, not within the docker environment.
  
  How can I connect `test_client` to `test_server` in such a scenario?
  
  **Tags:** docker, networking
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-16. Score: 1 | Accepted answer
  
  You can use a proxy to forward traffic between the two services, I typically do something like this which includes automated SSL with certbot. In the example below I have two services listening on port 80/443 (Sonarqube and Jenkins). You can also see I can reference container hosts by name (https://jenkins:8080)
  
  ```
  nginx:
  container_name: nginx-certbot
  restart: unless-stopped
  image: staticfloat/nginx-certbot
  networks:
    - local
  ports:
    - "0.0.0.0:80:80"
    - "0.0.0.0:443:443"
  environment:
    CERTBOT_EMAIL: <insert_email>
  volumes:
    - ./conf.d:/etc/nginx/user.conf.d:ro
    - letsencrypt:/etc/letsencrypt
  
  ```
  
  And this is what my nginx config looks like
  
  ```
  server {
  listen              443 ssl;
  server_name jenkins.hauntedmansion.io;
  ssl_certificate     /etc/letsencrypt/live/jenkins.hauntedmansion.io/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/jenkins.hauntedmansion.io/privkey.pem;
  
  client_max_body_size 20M;
  
    location / {
      proxy_set_header   Host $host;
      proxy_set_header   X-Real-IP $remote_addr;
      proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_pass         http://jenkins:8080;
      proxy_read_timeout 90;
      proxy_redirect     http://127.0.0.1:8080 https://jenkins.hauntedmansion.io;
    }
  }
  
  ```
  
  If you want to see the full docker compose example check it out here:
  
  <https://gist.github.com/cvega/66e0e5a2815e9b923da2c616f74dea7e>
  
  
  ---
  
  