

Most of the time I use Docker compose to start my Docker containers. You are able to reach the Docker host! How about Docker compose?

When you repeat the steps again, you now can reach the Spring Boot application that is running on the host from inside the Ubuntu container: curl Hello world container. In the example of the Ubuntu container: docker run -it -add-host=:host-gateway ubuntu bash On Linux, you can’t automatically resolve, you need to provide the following run flag when you start the container: -add-host=:host-gateway Inside the Ubuntu container, install curl: apt update & apt install curl -yĭo a call to the Spring Boot application running on the host using curl: curl īecause we didn’t start the container with the extra run flag, we will run into the following issue on Linux (on both Mac and Windows, it will just work fine): ping ping: : Name or service not known How to make it work?

Start an Ubuntu container: docker run -it ubuntu bash On top of the metrics, I would like to create Grafana dashboards.įor development purposes, I like to run Prometheus and Grafana in Docker while I’m developing my application in my favorite IDE, IntelliJ.įirst, start the Spring Boot application using the Spring CLI: spring run oovy The metrics are exposed via a Spring Boot actuator endpoint in a way Prometheus can read them. For observability reasons, I add custom metrics to my code. Practical example: I’m a Spring Boot developer and building a new feature into my application. Why do I even want to reach my Docker host from inside a Docker container?īefore diving into the issue and solution, it’s good to understand a use case why do I even need to reach the Docker host from inside my running Docker container? You need to have at least Docker version 20.10.0 installed to make this example work on Linux machines. Docker versionĪt the time of writing this blog post, the latest stable Docker version is: docker -v Docker version 20.10.8, build 3967b7d

This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows / Mac. We recommend that you connect to the special DNS name which resolves to the internal IP address used by the host. The host has a changing IP address (or none if you have no network access). From the Docker documentation for MacOS and Windows:
