Dockerized Spring Boot application not responding to requests, while non-Dockerized version works

Problem: I have Dockerized a Spring Boot application, but when I run the container, it doesn’t respond to any HTTP requests. The non-Dockerized version works fine. How should this issue be handled?

Steps Taken:

Built the Docker image:

docker build -t rezos/tourmappers-rezg-thirdparty-activity-service:2.1.2 .

Ran the container with port mapping (8380:8080):

docker run -d \
  --name tourmappers-rezg-thirdparty-activity-service \
  -p 8380:8080 \
  rezos/tourmappers-rezg-thirdparty-activity-service:2.1.2

Verified the container is running:

docker ps

Output:

CONTAINER ID   IMAGE                                                           COMMAND                  CREATED         STATUS         PORTS                                         NAMES
9c29bd8e24d6   rezos/tourmappers-rezg-thirdparty-activity-service:2.1.2   "java -jar rezg-thir…"   7 minutes ago   Up 7 minutes   0.0.0.0:8380->8080/tcp, [::]:8380->8080/tcp   tourmappers-rezg-thirdparty-activity-service

Output: as Image
Screenshot-from-2025-05-25-17-04-09
Dockerfile

FROM openjdk:11.0.8-jre-slim

EXPOSE 8080

COPY build/libs/rezg-thirdparty-activity-service-0.0.1-SNAPSHOT.jar rezg-thirdparty-activity-service.jar

CMD ["java", "-jar", "rezg-thirdparty-activity-service.jar"]

Issue:

Requests to http://localhost:8380/api/hotel/travelclick/process time out. The same request works on the non-Dockerized Spring Boot app (running on the same machine).

Questions:

  • How can I debug why the Dockerized app isn’t responding?
  • Are there common misconfigurations in Dockerfiles or Spring Boot that could cause this issue?

Regardless whether the java process is containerized, or on a remote machine, you would use the Java Debug Wire Protocol.

https://www.baeldung.com/java-application-remote-debugging

If you run jdwp, make sure to publish the port, so it can be reached from localhost:<published host port> of your ide’s remote debugger.

Though, wouldn’t it make sense to start troubleshooting with analyzing the container logs first?

Not really, unless you configured the server.port to use a different port in your application.properties

I did check the container Logs, but nothing was print there related to the request made.So I assume It was not reaching the application.

Logs only indicate the standard message printed when starting that application

$ docker logs 9c29bd8e24d6

  .   __          _            __ _ _
 /\\ / _'_ _ _ _()_ _  _ _ \ \ \ \
( ( )\_ | '_ | '| | ' \/ _` | \ \ \ \
 \\/  _)| |)| | | | | || (| |  ) ) ) )
  '  |_| .|| ||| |\_, | / / / /
 =========||==============|_/=////
 :: Spring Boot ::                (v2.7.4)

09:42:48.853 [main] INFO  r.t.a.s.RezgThirdpartyActivityServiceApplication - Starting RezgThirdpartyActivityServiceApplication using Java 11.0.8 on 9c29bd8e24d6 with PID 1 (/rezg-thirdparty-activity-service.jar started by root in /)
09:42:48.858 [main] INFO  r.t.a.s.RezgThirdpartyActivityServiceApplication - No active profile set, falling back to 1 default profile: "default"
09:42:50.554 [main] INFO  o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
09:42:50.574 [main] INFO  o.a.catalina.core.StandardService - Starting service [Tomcat]
09:42:50.574 [main] INFO  o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.65]
09:42:50.688 [main] INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
09:42:50.688 [main] INFO  o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1721 ms
09:42:51.808 [main] INFO  o.s.b.a.e.web.EndpointLinksResolver - Exposing 3 endpoint(s) beneath base path '/actuator'
09:42:51.862 [main] INFO  o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
09:42:51.885 [main] INFO  r.t.a.s.RezgThirdpartyActivityServiceApplication - Started RezgThirdpartyActivityServiceApplication in 3.841 seconds (JVM running for 4.417)
gehan@gehan-Inspiron-3580:~$

Another point is that the same application is deployed on the Staging server and the Production server. But it functions fine on these servers. I am trying to verify a bug on the Developer environment. Could it be some configurations are off in developer environment? Anything specific areas to compare in these environments that may help identify the issue?

The embedded tomcat starts, listens on port 8080 and marks the application as started, so things should be fine.

I am only uncertain about this:

Shouldn’t the default behavior of the embedded tomcat be to bind 0.0.0.0. This is needed, as the host’s localhost and the container’s localhost or not the same. The process inside the container must bind the port to 0.0.0.0, in order for published host ports to reach the container port.

Did you configure server.address=localhost in the application.properties? Either remove the line completely or set 0.0.0.0 and re-create the image.

Updated application.properties

Configured Spring Boot to listen to all ports by adding the following in application.properties:

#Enable actuator endpoints
management.endpoints.web.exposure.include=health, info, metrics
#management.endpoints.web.exposure.exclude=
management.endpoint.health.show-details=always
#server.ssl.enabled=true
#server.ssl.protocol=TLS
#server.ssl.enabled-protocols=TLSv1.3
server.address=0.0.0.0

# Base URL for the third-party reservation service
thirdparty.reservation.base-url=https://thirdparty-service.com
  • Passed as a command line argument:
docker run -d \
  --name tourmappers-rezg-thirdparty-activity-service \
  -p 8380:8080 \
  rezos/tourmappers-rezg-thirdparty-activity-service:2.1.2 \
  --server.address=0.0.0.0

But this too did not give the desired results. I have added how the same application is deployed in staging and production using very similar commands as used in the developer environment, but it works fine in these live environments

The commands used to deploy to the production and staging servers are similar to the steps followed in the development environment.

Production Environment

sudo docker login -u "****" -p "******" docker.io
sudo docker run -p 8380:8080 --name tourmappers-rezg-thirdparty-activity-service  -v /var/log/rezg/sys/:/var/log/rezg/sys/ -v /var/log/rezg/app/:/var/log/rezg/app/ --memory="256m"  rezos/tourmappers-rezg-thirdparty-activity-service:2.1.2-prod
            tail -f /dev/null

Staging Environment

sudo docker login -u "****" -p "******" docker.io
sudo docker run -p 8380:8080 --name tourmappers-rezg-thirdparty-activity-service  -v /var/log/rezg/sys/:/var/log/rezg/sys/ -v /var/log/rezg/app/:/var/log/rezg/app/ --memory="256m"  rezos/tourmappers-rezg-thirdparty-activity-service:{{version}}-{{stage}}
tail -f /dev/null

It should work like this. No idea why it’s not working for you.

Btw. the container arguments (the one right to the image) mean nothing without knowing your entry point script. Furthermore, the tail -f /dev/null looks somewhat odd, if the entrypoint is done correct, a Spring Boot app should not need it, as it’s a foreground process.