diff --git a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java index 4f190a5413c..8603a0b0787 100644 --- a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java +++ b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java @@ -241,22 +241,7 @@ public String getConnectionString() { protected void configure() { super.configure(); - addExposedPorts( - MGMT_PORT, - MGMT_SSL_PORT, - VIEW_PORT, - VIEW_SSL_PORT, - QUERY_PORT, - QUERY_SSL_PORT, - SEARCH_PORT, - SEARCH_SSL_PORT, - ANALYTICS_PORT, - ANALYTICS_SSL_PORT, - KV_PORT, - KV_SSL_PORT, - EVENTING_PORT, - EVENTING_SSL_PORT - ); + exposePorts(); WaitAllStrategy waitStrategy = new WaitAllStrategy(); @@ -319,6 +304,34 @@ protected void configure() { waitingFor(waitStrategy); } + /** + * Configures the exposed ports based on the enabled services. + *

+ * Note that the MGMT_PORTs are always enabled since there must always be a cluster + * manager. Also, the View engine ports are implicitly available on the same nodes + * where the KV service is enabled - it is not possible to configure them individually. + */ + private void exposePorts() { + addExposedPorts(MGMT_PORT, MGMT_SSL_PORT); + + if (enabledServices.contains(CouchbaseService.KV)) { + addExposedPorts(KV_PORT, KV_SSL_PORT); + addExposedPorts(VIEW_PORT, VIEW_SSL_PORT); + } + if (enabledServices.contains(CouchbaseService.ANALYTICS)) { + addExposedPorts(ANALYTICS_PORT, ANALYTICS_SSL_PORT); + } + if (enabledServices.contains(CouchbaseService.QUERY)) { + addExposedPorts(QUERY_PORT, QUERY_SSL_PORT); + } + if (enabledServices.contains(CouchbaseService.SEARCH)) { + addExposedPorts(SEARCH_PORT, SEARCH_SSL_PORT); + } + if (enabledServices.contains(CouchbaseService.EVENTING)) { + addExposedPorts(EVENTING_PORT, EVENTING_SSL_PORT); + } + } + @Override protected void containerIsStarting(final InspectContainerResponse containerInfo) { logger().debug("Couchbase container is starting, performing configuration.");