Docker

Docker Cross Container Communication

Docker allows communications between containers, provided the container’s port is exposed.  The example below creates an NGINX container, which is used as a reverse proxy for another container (Tomcat in this case).

1. Install and Run Tomcat Image & Container

sudo docker run -dit --name my_tomcat_container -p 8080:8080 tomcat

2. Find Docker IP Address for Tomcat Container

docker inspect my_tomcat_container | grep IPAddress
Output is found below.  In this case, our IP is 172.17.0.3.  Yours may differ.
"SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.3",
                    "IPAddress": "172.17.0.3",

3. Create NGINX Config File and Set proxy_pass IP (bare minimum config below…):

mkdir conf.d
echo "server{listen 80; location / { proxy_pass http://172.17.0.3:8080;}}" > conf.d/default.conf

4. Install and Run NGINX Image & Container, and Mount Created conf.d Directory

    sudo docker run -dit --name my_nginx_container -p 80:80 -v /path/to/conf.d:/etc/nginx/conf.d nginx

5. Verify

Open your browser and you should see the Tomcat page on http://localhost instead of the default Nginx page.