containers / image

Work with containers' images
Apache License 2.0
845 stars 366 forks source link

How can I copy from a tar file stream #2322

Closed zuzuviewer closed 1 month ago

zuzuviewer commented 4 months ago

How can I copy image from a tar file stream not a tar file. My server have a image upload api use multipart/form, it receive a docker image tar file stream, now I must create a temp file to save image and then copy it to backend repository, how can I directly copy upload stream to backend repository

mtrmac commented 4 months ago

Thanks for reaching out.

Please be more specific about what you are trying to do. Steps to reproduce / actual results / expected results?

If this is about the docker-archive: transport, consuming that inherently requires random access (or, equivalently, extracting the archive to a filesystem, and then accessing files in random order), so some kind of staging mechanism is inevitable.

zuzuviewer commented 4 months ago

now:

  1. upload a docker archive file by api to my server
  2. write this docker archive stream in a temp file.
  3. copy this temp file to docker repository by docker-archive transport.

expect:

  1. upload a docker archive file by api to my server
  2. copy this docker archive stream to docker repository.

I want to copy stream to docker repository directly otherwise write stream to temp file, then copy from this temp file. Because temp file will use operate system buffer/cache

mtrmac commented 4 months ago

As already described above, that’s just not possible. You can provide a stream to docker-archive (using a named pipe, or perhaps /dev/fd/…), but docker-archive: is going to create that temporary file internally.

In general, I would recommend not building any workflows around the docker-archive: format in the first place; use a registry. I realize that’s not always possible or trivial to change, but it is a better design, eliminating this performance issue, for example.

zuzuviewer commented 4 months ago

Thanks your advice. What do you mean ‘use a registry’?

zuzuviewer commented 4 months ago

Thanks your advice. What do you mean ‘use a registry’?

mtrmac commented 4 months ago

https://github.com/opencontainers/distribution-spec/, e.g. https://github.com/distribution/distribution .

mtrmac commented 1 month ago

Please reopen if there are outstanding questions.