How to push a tar archive to private docker registry?
Asked Answered
C

4

23

Now I have such a requirement,firstly I need export a container’s filesystem as a tar archive, then I need push this tar to my own docker registry.So could I push a tar file which is exported by using docker export image_name to my private registry.Before this I only know I could push a local image to registry by using docker push image_name. Thanks!

Consanguineous answered 26/9, 2018 at 15:43 Comment(6)
A docker registry is meant to contain images, not arbitrary data. Can you explain your use case, maybe there is another solution.Sisile
I’d put docker export on my list of commands that it’s very unusual to use. What’s your actual goal in this process?Masterful
My use case is that firstly I ask users to upload their custom image which is exported or saved as a tar archive to a specified ftp server, then I need write a proxy program (I plan to use docker-java lib) to push these tar files to my private docker registry. The reason why I build my registry is that it's convenient for my Kubernetes cluster to download images. So I'm not sure whether I could push a tar archive to registry directly. If not, what should I do? Is there a better solution? Thanks!Consanguineous
Hi @DavidMaze, thanks for your answer! But why it’s very unusual to use docker export? If not use, how can we back-up or migrate images? Use docker save instead?Consanguineous
Why not docker import the tar and then push the resulting image?Sisile
Thanks Herry.@Sisile Yes, previously I only know the way you said, which we must firstly import or load the tar to the docker environment, while now I'd like to know whether we could push the tar directly? if docker not support, maybe I have to do what you said.Consanguineous
C
21

If you don't want to use any external tools, you can use a combination of:

docker image load --input image.tar.gz # this will output the original image name
docker image tag original-registry.example.org/original-image-name:0.0.1 new-registry.example.com/new-image-name:0.0.1
docker push new-registry.example.com/new-image-name
Cohligan answered 28/4, 2020 at 11:1 Comment(1)
docker is an external tool.Letaletch
N
7

The crane tool seems to have this functionality:

crane pull - Pull a remote image by reference and store its contents in a tarball
crane push - Push image contents as a tarball to a remote registry
Nashville answered 28/2, 2020 at 20:22 Comment(1)
crane push does not load tags from tarball and pushes only "latest" tag. Through you can manually pass tag to push with (i.e. crane push image.tar registry.io:9090/newImage/path:someTag).Atrocious
W
5

The three tools I know of for working with registries without a docker engine are crane from Google, skopeo from RedHat, and regclient from myself.

The workflow that's needed is to extract the tar, push each layer and config, and then push the manifests. OCI's distribution-spec includes details on the registry API, but realize that the authentication doesn't have a spec over there (at least not yet), and there are different tar files whether you are talking about a docker export, docker save, or an OCI layout. There's also whether the tar file has been compressed.

For the latter two formats, you can use regctl image import from the regclient project. E.g.:

regctl image import localhost:5000/project:tag image.tar

Or to go the other way and create an export (that is a merge of the docker save and OCI layouts):

regctl image export localhost:5000/project:tag image.tar
Warp answered 31/3, 2022 at 13:53 Comment(2)
If you are using insecure (http only) registry, you have to prepare regctl to this using registry set option. See example on github.com/regclient/regclient/issues/268 . PS: tool is not importing tags from image.Atrocious
Thanks for publishing this. Lost 4 hours today trying to get crane to work, your tool worked in the first 20 minutes.Implausibility
C
3

I've just released the following library:

https://pypi.org/project/dockertarpusher/0.16/

I've also struggled with volume the docker socket into container that needs only to repush tar image, so that was the reason for this library

Citizen answered 1/7, 2019 at 20:7 Comment(1)
I am looking for C# library. Found this but it seems incomplete.Schott

© 2022 - 2024 — McMap. All rights reserved.