Reputation: 199
I am trying to link two applications with docker compose I have the following yaml file
version: '3'
services:
app1:
build:
context: ../../repos/app1
ports:
- "8080:8080"
app2:
build: .
ports:
- "8081:8080"
I know that he ports are arranged as the following host_port:container_port - https://docs.docker.com/compose/networking/
This stack overflow is what made me specify the ports so that the containers are on the same container port. Multiple docker containers with same container port connected to the same network
Then I run a docker compose up
I see two images created and two processes running
REPOSITORY TAG IMAGE ID CREATED SIZE
main_app2 latest 1d204754b5c3 5 days ago 725MB
main_app1 latest 58e838149b97 5 days ago 754MB
PS C:\Users\am818j\repos\main> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d6b6c3411670 main_app2 "/opt/jboss/wildfly/…" 8 minutes ago Up 8 minutes 8443/tcp, 9990/tcp, 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp main_app2_1
392e8d6da3c7 main_app1 "/opt/jboss/wildfly/…" 8 minutes ago Up 8 minutes 8443/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 9990/tcp main_app1_1
I can see two processes running and access them from the following urls http://localhost.test.com:8081/app2/faces/home.faces and http://localhost.test.com:8080/app1/faces/home.faces
But I do not see data flow between app1 and app2. Is it possible to have these two apps communicate with each other? If so what am I missing to be able to test that communication?
Upvotes: 1
Views: 1235
Reputation: 9997
You say absolutely nothing about the processes. Are they TRYING to communicate with each other? How? What's the error message?
I am guessing you have them trying to talk to localhost:8000
and localhost:8001
. However, each container has its OWN localhost loopback- they don't share one. Instead, they should be talking to app1:8000
and app2:8000
. Note 8000
vs 8001
- the ports
argument maps a port on YOUR interface to a port in THE CONTAINER interface... so far as the container is concerned, it is still listening on port 8000, and your other containers will have to use that.
Upvotes: 1