Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CreateImageCmd execute failure and report 500 #2377

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

Open
oslivan opened this issue Dec 24, 2024 · 1 comment
Open

CreateImageCmd execute failure and report 500 #2377

oslivan opened this issue Dec 24, 2024 · 1 comment

Comments

@oslivan
Copy link

oslivan commented Dec 24, 2024

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?

Copy link

stale bot commented Apr 26, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

1 participant