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

Question: How to make consecutive Docker calls? #258

Closed
rwmajor2 opened this issue Oct 29, 2020 · 2 comments
Closed

Question: How to make consecutive Docker calls? #258

rwmajor2 opened this issue Oct 29, 2020 · 2 comments

Comments

@rwmajor2
Copy link

Is this a BUG REPORT or FEATURE REQUEST?:

Description

I am trying to use the DockerClient and I keep seeming to have an issue making consecutive calls with the same client object, throwing an error and closing the connection. Below is an example:

DockerClient docker;
    try {
      docker = new JerseyDockerClientBuilder().fromEnv().build();
    } catch (DockerCertificateException e) {
      throw new AdminException(TuringAdminLogCode.DOCKER_UNABLE_TO_ESTABLISH_ENVIRONMENT);
    }
...
        ExecCreation execIdmkdir = docker.execCreate(containerId,
                new String[]{"bash", "-c", "mkdir -p " + licensePath},
                DockerClient.ExecCreateParam.attachStdout(),
                DockerClient.ExecCreateParam.attachStderr());
        final LogStream stream1 = docker.execStart(execIdmkdir.id());

        ExecCreation execIdWriteKeycode = docker.execCreate(containerId,
                new String[]{"bash", "-c", "echo \"" + keycodes[0] + "\" > " + licensePath + "keycodes"},
                DockerClient.ExecCreateParam.attachStdout(),
                DockerClient.ExecCreateParam.attachStderr());
        final LogStream stream2 = docker.execStart(execIdWriteKeycode.id());

The first works. The second throws an error ('javax.ws.rs.ProcessingException: java.lang.IllegalStateException: Connection is still allocated'). I keep running into this and not sure how to overcome it. I am missing something fundamentally of how to use a single instantiated DockerClient object and make numerous calls.

How to reproduce

[Add steps on how to reproduce this issue]

What do you expect

[Describe what do you expect to happen]

What happened instead

[Describe the actual results]

Software:

  • docker version: [Add the output of docker version here, both client and server]
  • Spotify's docker-client version: [Add docker-client version here]

Full backtrace

[Paste full backtrace here]
@dmandalidis
Copy link
Owner

Hi @rwmajor2

Sorry for not following this up earlier. Making consecutive Docker calls with the same client is well supported and unit-tested. I believe this is either a bug with these specific calls or you 're doing something weird in your example that I cannot spot at the moment. I 'll try to reproduce it in the next couple of days.

@dmandalidis
Copy link
Owner

Hi @rwmajor2

I couldn't manage to reproduce your issue with the 4.0.2 version:

try (DockerClient client = new JerseyDockerClientBuilder().fromEnv().build()) {
          client.pull("busybox:latest");
          ContainerConfig containerConfig = ContainerConfig.builder()
              .image("busybox:latest")
              .cmd("sh", "-c", "while :; do sleep 10m; done")
              .build();
          ContainerCreation containerCreation = client.createContainer(containerConfig, "mycontainer");
          String containerId = containerCreation.id();
          client.startContainer(containerId);
          ExecCreation execIdmkdir = client.execCreate(containerId,
              new String[]{"bash", "-c", "echo bar"},
              DockerClient.ExecCreateParam.attachStdout(),
              DockerClient.ExecCreateParam.attachStderr());
          final LogStream stream1 = client.execStart(execIdmkdir.id());
    
          ExecCreation execIdWriteKeycode = client.execCreate(containerId,
              new String[]{"bash", "-c", "echo foo"},
              DockerClient.ExecCreateParam.attachStdout(),
              DockerClient.ExecCreateParam.attachStderr());
          final LogStream stream2 = client.execStart(execIdWriteKeycode.id());
}

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