Reputation: 3622
I want to distribute some throw-away docker images (image which is only started once and directly removed). To achieve this i must be able to push my docker image to a docker registry from which other hosts can pull. Other docker hosts pull this image, run it and remove it after it terminates.
Unfortunately (afaik) there is no easy clean way to remove images from a private docker registry.
Is there maybe an easy way to startup a throwaway docker registry which i can use for distribution? Is there maybe a way to accept any insecure registry?
So far i always have to configure the insecure registry via: --insecure-registry
Is there maybe an alternative option to distribute a docker image without using a docker registry?
Upvotes: 1
Views: 278
Reputation: 12625
Sure, there are a couple of ways you can go about distributing images. Probably the most important thing I should mention is that setting up a registry (specifically a "v2 registry" which is the newest version supported by the distribution team) is kind of a pain. It's not super difficult, and it's light years ahead of the first version of registry (the old python project), but it's not something you want to dive into for this particular problem, especially since you're searching for a quick and easy solution.
So, you're left distributing images or containers as tarball archives. There are two sets of commands you can use here, and there are some minor (but important) differences. First, let's look at transferring only the image, not the container. So for this you'll be using docker save
on the docker host, and then transfer the tarball to the target machine, and then use docker load
to create an image from the tarball. For example, on the host:
docker save --output myImage.tar myImage:latest
And then you can rsync
or sftp
(or whatever) to transfer the myImage.tar
tarball to your target machine. Then on that host:
docker load --input myImage.tar
That's pretty simple, but let's say you have a container running from an image that you would like to transfer. The problem is that you could transfer the image, but it would lose all of the changes made to the image's filesystem since it started. The way around this is to use docker export
and docker import
. This will save all the intermediate changes into the filesystem along with the base filesystem image.
So, you'll be using the docker export
command on your docker host, and of course docker import
on your target machine. As in the other example, you'll need to transfer the tarball generated by docker export
to the target machine. For example, on the docker host:
docker export myContainer > myContainer.tar
And then on the target machine, after you've transferred myContainer.tar
to it:
cat myContainer.tar | docker import - jotschi/myContainerImage
Now you've got an image called jotschi/myContainerImage
on the target, which you can then create a container from:
docker run -d --name=myContainer -p 80:80 jotschi/myContainerImage
Upvotes: 1