Search in sources :

Example 1 with ExecConfig

use of org.eclipse.che.plugin.docker.client.json.ExecConfig in project che by eclipse.

the class DockerConnector method createExec.

/**
     * Sets up an exec instance in a running container.
     *
     * @return just created exec info
     * @throws IOException
     *          when a problem occurs with docker api calls
     */
public Exec createExec(final CreateExecParams params) throws IOException {
    final ExecConfig execConfig = new ExecConfig().withCmd(params.getCmd()).withAttachStderr(params.isDetach() == Boolean.FALSE).withAttachStdout(params.isDetach() == Boolean.FALSE);
    byte[] entityBytesArray = toJson(execConfig).getBytes(StandardCharsets.UTF_8);
    try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("POST").path(apiVersionPathPrefix + "/containers/" + params.getContainer() + "/exec").header("Content-Type", MediaType.APPLICATION_JSON).header("Content-Length", entityBytesArray.length).entity(entityBytesArray)) {
        final DockerResponse response = connection.request();
        if (response.getStatus() / 100 != 2) {
            throw getDockerException(response);
        }
        return new Exec(params.getCmd(), parseResponseStreamAndClose(response.getInputStream(), ExecCreated.class).getId());
    }
}
Also used : ExecConfig(org.eclipse.che.plugin.docker.client.json.ExecConfig) DockerConnection(org.eclipse.che.plugin.docker.client.connection.DockerConnection) DockerResponse(org.eclipse.che.plugin.docker.client.connection.DockerResponse)

Aggregations

DockerConnection (org.eclipse.che.plugin.docker.client.connection.DockerConnection)1 DockerResponse (org.eclipse.che.plugin.docker.client.connection.DockerResponse)1 ExecConfig (org.eclipse.che.plugin.docker.client.json.ExecConfig)1