diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java index c8506b9511233e..eb78f9a02d22da 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java @@ -178,7 +178,7 @@ private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem } Supplier defaultMongoServerSupplier = () -> { - MongoDBContainer mongoDBContainer; + QuarkusMongoDBContainer mongoDBContainer; if (capturedProperties.imageName != null) { mongoDBContainer = new QuarkusMongoDBContainer( DockerImageName.parse(capturedProperties.imageName).asCompatibleSubstituteFor("mongo"), @@ -189,8 +189,9 @@ private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem timeout.ifPresent(mongoDBContainer::withStartupTimeout); mongoDBContainer.withEnv(capturedProperties.containerEnv); mongoDBContainer.start(); - final String effectiveUrl = getEffectiveUrl(configPrefix, mongoDBContainer.getHost(), - mongoDBContainer.getMappedPort(MONGO_EXPOSED_PORT), capturedProperties); + + final String effectiveUrl = getEffectiveUrl(configPrefix, mongoDBContainer.getEffectiveHost(), + mongoDBContainer.getEffectivePort(), capturedProperties); return new RunningDevService(Feature.MONGODB_CLIENT.getName(), mongoDBContainer.getContainerId(), mongoDBContainer::close, getConfigPrefix(connectionName) + "connection-string", effectiveUrl); }; @@ -314,9 +315,12 @@ public String getReplicaSetUrl(String databaseName) { } } - @Override - public String getHost() { + public String getEffectiveHost() { return useSharedNetwork ? hostName : super.getHost(); } + + public Integer getEffectivePort() { + return useSharedNetwork ? MONGODB_INTERNAL_PORT : getMappedPort(MONGO_EXPOSED_PORT); + } } }