Home

Docker Compose two services communication example

Refer this for more details on dockerizing maven applications

Clone the project, and execute the following commands

docker-compose> mvn clean package
docker-compose> docker-compose build
docker-compose> docker-compose up

Here is the content of docker-compose.yml

version: '2'
services:
  dateservice:
    build: ./date-service
    ports:
      - "8088:8080"
  ui:
    build: ./ui
    links:
      - "dateservice"
    ports:
      - "7070:8080"

context.xml file of ui app, keep a note of url environment entry.


<Context path="/ui" debug="0" reloadable="false" useHttpOnly="true"
	clearReferencesHttpClientKeepAliveThread="true"
	clearReferencesStopThreads="true" clearReferencesStopTimerThreads="true">


	<Environment name="app" type="java.lang.String"
		value="${catalina.base}/webapps/echo-service" />

	<Environment name="url" type="java.lang.String"
		value="http://dateservice:8080/date-service" />

</Context>

This is how the two services communicate

From localhost this is how it can be accessed.