Open
Description
When I use curl to request creating image as below:
curl --silent \
-H 'Content-Type: application/octet-stream' \
--data-binary "@/mnt/c/tmp/redis.tar" \
"http://localhost:2375/v1.45/images/create?fromSrc=-&repo=test%3Alatest"
it's ok, and then I use dockerjava to create image as below:
public String buildImage(String repository, String source) throws IOException {
File file = new File(source);
if(!file.exists()) {
throw new RuntimeException("File not exist");
}
try (InputStream inputStream = new FileInputStream(file)) {
CreateImageResponse response = client.createImageCmd(repository, inputStream).exec();
return response.getId();
}
}
it's reporting 500, after I trace the request, I found this function:
// com.github.dockerjava.core.DefaultInvocationBuilder
public InputStream post(Object entity) {
DockerHttpClient.Request request = this.requestBuilder.method(Method.POST).putHeader("content-type", "application/json").bodyBytes(this.encode(entity)).build();
final DockerHttpClient.Response response = this.execute(request);
return new FilterInputStream(response.getBody()) {
public void close() throws IOException {
try {
super.close();
} finally {
response.close();
}
}
};
}
the param entity
is FileInputStream rather than json object, so my image tar can't be sent in binary form, how can i solve this, has anyone encountered this problem?