Skip to content

How to run a Exec #386

Description

@NhanHoThanh

How to run the Exec instance after create it, I have dig throught the repo but cant find a way to make it work, here is my code below:

    public String testDockerClient () {
        try{
            final Docker dockerClient = new UnixDocker(new File("/var/run/docker.sock"));
            final Container started = dockerClient.containers().create("my-python-runner:latest");



            JsonArray cmdArray = Json.createArrayBuilder()
                .add("echo")
                .add("helloword")
                .build();

            JsonObject execConfig = Json.createObjectBuilder()
                .add("Cmd", cmdArray)
                .add("AttachStdin", false)
                .add("AttachStdout", true)
                .add("AttachStderr", true)
                .add("Tty", false)
                .build();

            started.start();

            Exec output = started.exec(execConfig);
            System.out.println("output: " + output.inspect());
            Logs log = started.logs();
            System.out.println("log: " + log.toString());
            started.stop();
            started.remove();

            return "Success";


        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions