title: Configuring Minio server for use with Testcontainers
body: <p>My application uses <a href="https://min.io" rel="noreferrer">Minio</a> for S3-compatible object storage, and I'd like to use the Minio docker image in my integration tests via <a href="https://www.testcontainers.org" rel="noreferrer">Testcontainers</a>.</p>
  
  <p>For some very basic tests, I run a GenericContainer using the <code>minio/minio</code> docker image and no configuration except <code>MINIO_ACCESS_KEY</code> and <code>MINIO_SECRET_KEY</code>. My tests then use Minio's <a href="https://docs.minio.io/docs/java-client-quickstart-guide.html" rel="noreferrer">Java Client SDK</a>. These work fine and behave just like expected.</p>
  
  <p>But for other integration tests, I need to set up separate users in Mino. As far as I can see, users can only be added to Minio using the <a href="https://docs.minio.io/docs/minio-admin-complete-guide.html" rel="noreferrer">Admin API</a>, for which there is no Java client, only the <code>minio/mc</code> docker image (the <code>mc</code> CLI is not available in the <code>minio/minio</code> docker image used for the server).</p>
  
  <p>On the command line, I can use the Admin API like this:</p>
  
  <pre><code>$ docker run --interactive --tty --detach --entrypoint=/bin/sh --name minio_admin minio/mc
  </code></pre>
  
  <p>The <code>--interactive --tty</code> is a bit of a hack to keep the container running so I can later run commands like this one:</p>
  
  <pre><code>$ docker exec --interactive --tty minio_admin mc admin user add ...
  </code></pre>
  
  <p>Using Testcontainers, I try to do the same like this:</p>
  
  <pre><code>public void testAdminApi() throws Exception {
      GenericContainer mc = new GenericContainer("minio/mc")
              .withCommand("/bin/sh")
              .withCreateContainerCmdModifier(new Consumer&lt;CreateContainerCmd&gt;() {
                  @Override
                  public void accept(CreateContainerCmd cmd) {
                      cmd
                              .withAttachStdin(true)
                              .withStdinOpen(true)
                              .withTty(true);
                  }
              });
  
      mc.start();
      log.info("mc is running: {}", mc.isRunning());
  
      String command = "mc";
      Container.ExecResult result = mc.execInContainer(command);
      log.info("Executing command '{}' returned exit code '{}' and stdout '{}'", command, result.getExitCode(), result.getStdout());
  
      assertEquals(0, result.getExitCode());
  }
  </code></pre>
  
  <p>The logs show the container being started, but executing a command against it returns exit code 126 and claims it's in a stopped state:</p>
  
  <pre><code>[minio/mc:latest] - Starting container with ID: 4f96fc7583fe62290925472c4c6b329fbeb7a55b38a3c0ad41ee797db1431841
  [minio/mc:latest] - Container minio/mc:latest is starting: 4f96fc7583fe62290925472c4c6b329fbeb7a55b38a3c0ad41ee797db1431841
  [minio/mc:latest] - Container minio/mc:latest started
  minio.MinioAdminTests - mc is running: true
  org.testcontainers.containers.ExecInContainerPattern - /kind_volhard: Running "exec" command: mc
  minio.MinioAdminTests - Executing command 'mc' returned exit code '126'
    and stdout 'cannot exec in a stopped state: unknown'
  
  java.lang.AssertionError: Expected: 0, Actual: 126
  </code></pre>
  
  <p>After fiddling around with this for hours, I'm running out of ideas. Can anyone help?</p>