Temporary Failure in Name Resolution When Running Spring App with Dockerized Mongodb

I have simple SpringBoot app with following configuration, running on Ubuntu 20.04

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

....

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

And in application.properties spring.data.mongodb.uri=mongodb://my_db:27017/test

I'm not sure if that is relevant but I have some documents as well

@Repository
interface SomeDocumentRepository : CrudRepository<SomeDocument, String>

@Document
data class SomeDocument(
    @Id val id: String? = null,
    val name: String
)

And I'm running Mongo in docker container by executing docker run -d -p 27017:27017 --name my_db mongo:latest

However, when I start my Spring application, it crashes with com.mongodb.MongoSocketException: my_db: Temporary failure in name resolution

Any idea what is wrong with that configuration? Why is it failing?

1 Answer

Usually, this means there is a problem with the nameserver resolvers you have configured for your server in /etc/resolv.conf. They may be unavailable or there may be a networking issue preventing connectivity to them.

This will resolve itself after a period of time but indicates a possible deeper problem that you may wish to contact your nameserver resolver provider about (often your web hosting company).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest