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

Get Container ERR/OUT/IN #2301

Open
debxrshi opened this issue Jan 22, 2024 · 5 comments
Open

Get Container ERR/OUT/IN #2301

debxrshi opened this issue Jan 22, 2024 · 5 comments

Comments

@debxrshi
Copy link

debxrshi commented Jan 22, 2024

Hi, I'm a beginner, creating a container and attaching to in/out. Container is getting created fine, but how to capture the output? Code I'm using:

DockerClient client = Client.clientInit();
        CreateContainerResponse container = client.createContainerCmd("python:slim")
                .withCmd("/bin/sh","-c","uname -a")
                .withAttachStderr(true)
                .withAttachStdin(true)
                .withName("sandbox-dev")
                .exec();
        client.startContainerCmd(container.getId()).exec();

Also, how to get the STDERR/STDOUT/ attach to STDIN via docker exec equivalent code?

PS- clientInit is defined:

public class Client {
    public static DockerClient clientInit(){
        DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
        ZerodepDockerHttpClient httpClient = new ZerodepDockerHttpClient.Builder().dockerHost(config.getDockerHost()).build();
        return DockerClientImpl.getInstance(config,httpClient);
    }
}
@fujiwarazz
Copy link

same issue. I cann`t the output of the container code output by using withstdin(), have you solve this problem?

@debxrshi
Copy link
Author

@fujiwarazz yeah I found a solution but it's really bad code. Have you found any solution?

@fujiwarazz
Copy link

you can try client init with ApacheHttp5 instead

@debxrshi
Copy link
Author

@fujiwarazz why?

@raunaqpahwa
Copy link

Hey @debxrshi and @fujiwarazz this might help-
https://github.com/raunaqpahwa/CodeExecutionEngine/blob/440f46869bf229aabc73d280a655bdca64f36530/src/main/java/com/raunaqpahwa/codeexecutor/services/impl/JavaCodeExecutionStrategy.java#L58

You can pass a custom callback while executing command in the docker container and that will help you fetch stdout and stderr.

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