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

Support for attaching Stdin when execStart #253

Closed
missedone opened this issue Jun 18, 2015 · 7 comments
Closed

Support for attaching Stdin when execStart #253

missedone opened this issue Jun 18, 2015 · 7 comments

Comments

@missedone
Copy link

Hi folks

in my case, i'd like to execture a block of bash scripts when 'docker exec', the way to approach that, i think, is to attach stdin, and send the block of bash scripts through the output stream.

but i find execStart only return an inputStream, there is noway to send data when execStart.

so could you implement this, or is there any other way to workaround this?
thanks

@missedone
Copy link
Author

looks like spotify/docker-client has the similar issue: spotify/docker-client#156
as using apache httpclient while it does not support hijacking, and i don't see any plan that when will httpclient support websockets/hijacking

@missedone
Copy link
Author

for docker execStart API call, i just created a quick and dirty http hijacking with java.net.Socket:
https://gist.github.com/missedone/76517e618486db746056

here is a simple usage:

        ExecCreateCmdResponse execCreateResp = dck.execCreateCmd(cid).withCmd("bash")
                .withAttachStderr().withAttachStdout().withAttachStdin().withTty(false).exec();

        HashMap<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");

        HttpHijack ws = new HttpHijack(new URI("http://127.0.0.1:2376/v1.19/exec/" + execCreateResp.getId() + "/start"));
        String payload = "{\"Detach\": false,\"Tty\": false}";
        ws.post(headers, payload);

        String request = "date > /tmp/nick2; cat /tmp/nick2; exit $?;";
        InputStream input = ws.send(request);

        Thread.sleep(3000);
        InspectExecResponse execResp = dck.inspectExecCmd(execCreateResp.getId()).exec();
        log.info("exec inspect: {}", execResp);

        String response = IOUtils.readLines(input).toString();
        log.info(response);

i will refactor the code to be more production ready later

@marcuslinke
Copy link
Contributor

Thanks for investigating! I'm curious if and how this will integrate with current codebase.

@missedone
Copy link
Author

@marcuslinke
i take this code as prototype, not perfect, i would like to think more on the http hijack impl, will consider the integration with docker–java later

@marcuslinke
Copy link
Contributor

FYI: Meanwhile I experiment with netty as foundation framework (https://github.com/docker-java/docker-java/tree/netty). Currently most features are implemented now like UNIX sockets, SSL/https and of course http hijacking that is needed for passing STDIN to the container. All existing tests passed successfully but still some needed features are missing namely http(s) proxy support and automatic redirection (and maybe some more).

@KostyaSha After this is done I plan to merge into master as alternative DockerCmdExecFactory implementation, so users might use (and test) it. WDYT?

@KostyaSha
Copy link
Member

@marcuslinke @bsideup has some view point about rx/reactive java. Let's wait for his comments for netty branch.

@marcuslinke
Copy link
Contributor

Closing this as of merging #397

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

3 participants