Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore EXPOSE instruction from Dockerfile #3936

Closed
IvannKurchenko opened this issue Mar 27, 2021 · 1 comment
Closed

Ignore EXPOSE instruction from Dockerfile #3936

IvannKurchenko opened this issue Mar 27, 2021 · 1 comment

Comments

@IvannKurchenko
Copy link

IvannKurchenko commented Mar 27, 2021

Thank you so much for a great product!

Recently I faced with next issue: I'm trying to run Couchbase 5.1 container with fixed ports (via testcontainer-scala - but since this is the only wrapper I suspect an issue, not in that library):

trait CouchbaseTestEnvironment extends ForAllTestContainer {
  this: Suite =>

  def couchbaseContainer: FixedHostPortGenericContainer = {
    val consumer = new Slf4jLogConsumer(LoggerFactory.getLogger(getClass))

    /*
     * Couchbase should know which ports are exposed for client because this is how it exposes services.
     * E.g. client asks only for on port - say 8091. And query service port is 8093. So client, won't ask for every port,
     * instead CB will tell the client which port query service exposed, that's why CB should be aware of port mapping.
     * That's why we need to give CB port mappings
     *
     * See for more details:
     * https://stackoverflow.com/questions/59277436/couchbase-in-docker-for-integration-tests-make-the-ports-8092-8093-8094-and-8
     */

    def randomPort: Int = {
      val (from, to) = (32768, 35000) //linux private port range
      from + Random.nextInt(to - from)
    }

    val random8091Port = randomPort
    val random8092Port = randomPort
    val random8093Port = randomPort
    val random8094Port = randomPort
    val random11210Port = randomPort

    val container = FixedHostPortGenericContainer(
      imageName = "couchbase:community-5.0.1",
      exposedHostPort = random8091Port,
      exposedContainerPort = random8091Port,
      env = Map(
        "COUCHBASE_RANDOM_PORT_8091" -> random8091Port.toString,
        "COUCHBASE_RANDOM_PORT_8092" -> random8092Port.toString,
        "COUCHBASE_RANDOM_PORT_8093" -> random8093Port.toString,
        "COUCHBASE_RANDOM_PORT_8094" -> random8094Port.toString,
        "COUCHBASE_RANDOM_PORT_11210" -> random11210Port.toString
      )
    )
    container.container.withFixedExposedPort(random8092Port, random8092Port)
    container.container.withFixedExposedPort(random8093Port, random8093Port)
    container.container.withFixedExposedPort(random8094Port, random8094Port)
    container.container.withFixedExposedPort(random11210Port, random11210Port)
    container.container.withLogConsumer(consumer)
    container
  }
}

So as you can see 5 FIXED ports should be exposed. But, when I'm running tests I actually can see, that instead other ports exposed with random ports:

docker ps

f4fc1ce06544   couchbase:community-5.0.1   "/entrypoint.sh /opt…"   59 seconds ago   Up 1 second    0.0.0.0:55264->8091/tcp, 0.0.0.0:55263->8092/tcp, 0.0.0.0:55262->8093/tcp, 0.0.0.0:55261->8094/tcp, 0.0.0.0:55260->11207/tcp, 0.0.0.0:55259->11210/tcp, 0.0.0.0:55258->11211/tcp, 0.0.0.0:55257->18091/tcp, 0.0.0.0:55256->18092/tcp, 0.0.0.0:55255->18093/tcp, 0.0.0.0:55254->18094/tcp   unruffled_mendel
03b491ac2ea8   testcontainersofficial/ryuk:0.3.0

As far as I understand, test containers ignores ports I gave and instead exposes ports from Couchbase Dockerfile: https://github.com/couchbase/docker/blob/master/community/couchbase-server/5.1.1/Dockerfile#L74

EXPOSE 8091 8092 8093 8094 8095 8096 11207 11210 11211 18091 18092 18093 18094 18095 18096

Can I somehow force Test containers to ignore EXPOSE instruction? Is this expected behavior at all.

Used software and environment:

OS: Windows 10
Docker version: Docker version 20.10.5, build 55c4c88
Scala: 2.12
sbt: v1.4.0
testcontainer version: 0.38.3

@rnorth
Copy link
Member

rnorth commented Jun 17, 2021

@IvannKurchenko I think this should be fixed in #4122, which is a change we've made for an unrelated reason (#4119).

We haven't released #4122 yet, but it should be soon, and hopefully the Scala wrapper will follow after. I hope this will help!
I'll close this issue.

@rnorth rnorth closed this as completed Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants