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.
I'm trying to replicate
docker exec -icommand 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:
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:
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.