In the below example since I have many environment variables I cannot directly run ENTRYPOINT with java -jar command option. Instead I have used entrypoint.sh
Dockerfile
ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,address=9251,server=y,suspend=n
RUN ["chmod", "777", "entrypoint.sh"]
ENTRYPOINT ["bash","entrypoint.sh"]
EXPOSE 9251
entrypoint.sh
java $JVM_OPTS $JAVA_OPTS org.springframework.boot.loader.JarLauncher
docker-compose.yaml
version: '3.1'
services:
bus:
image: sample-image
network_mode: "host"
ports:
- 9251:9251
environment:
- DEBUG_PORT=9251
- JVM_OPTS=-Xms1G -Xmx5G -XX:MaxMetaspaceSize=512m -XX:+UseG1GC
In the below snapshot we can see when the service is started with debugging enabled

when running sudo netstat -tulpn | grep :9251 shows
The docker is running in a linux box which I am trying to connect from local windows machine. Also note that it is mandatory that I need to keep the network_mode as host.

