Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Stdin file redirection issue for docker exec -i command #1315

Copy link
Copy link
Closed
@s101d1

Description

@s101d1
Issue body actions

I'm trying to replicate docker exec -i command that involves stdin file redirection: docker exec -i mysql_docker sh -c "exec mysql -u root -proot db" < dump.sql. This is for importing sql file into mysql docker container.

I have this code:

    DefaultDockerClientConfig.Builder config = DefaultDockerClientConfig.createDefaultConfigBuilder();
    DockerClient dockerClient = DockerClientBuilder.getInstance(config)
      .build();
      
    Container container = ...   // some codes to get the container instance

    ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
      .withAttachStdin(true)
      .withAttachStdout(true)
      .withCmd("sh", "-c", String.format("exec mysql -u root -p%s %s", rootPassword, databaseName))
      .exec();
      
    dockerClient.execStartCmd(execCreateCmdResponse.getId())
      .withStdIn(System.in)
      .exec(new ExecStartResultCallback(System.out, System.err))
      .awaitCompletion();

The process is stuck at the .awaitCompletion() part. I had to hit Ctrl+C to terminate it. I read there was issue with stdin redirection. Had it been really fixed?

The stdout file redirection doesn't have issue though.

I also tried it with NettyDockerCmdExecFactory:

    DockerClient dockerClient = DockerClientBuilder.getInstance(config)
      .withDockerCmdExecFactory(new NettyDockerCmdExecFactory())
      .build();

The .awaitCompletion() went through, but the whole app process will get stuck too and won't terminate. Same case for the stdout file redirection too. And I saw the import results is broken, only some tables were created, it looks like the stdin file contents was truncated around 10,000 characters.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.