Manuel Mauky
Manuel Mauky

Reputation: 2193

deploy docker image with ansible-container without a docker registy

I'm trying to use ansible-container to create and deploy my docker application but I can't get it to work.

I have a remote server which I can configure via ansible. On my local machine I'm using ansible-container to build a docker image which is working fine. After running ansible-container build I have the docker image on my local machine. However, I don't get the next step to work. My goal is to push the docker image from my local machine to the remote server and then create and start a docker container based on this image on the remote server.

I'm not using a docker registry. Therefore I'm using the --local-images option for ansible-container deploy command which prevents it from pushing the image to a registry (at least this is what I understand from the docs). This command successfully creates an ansible playbook but when I execute this playbook it still tries to pull the image from the docker.io registry and of course can't find it there.

I think the missing step is to push the local docker image to the remote server but I can't find any hints in the ansible-container docs for this use-case. I have also looked at ansible docker_image module but as far as I understand this is also centered around using a registry.

How can I deploy a docker image to a remote server with ansible?

Upvotes: 4

Views: 1661

Answers (1)

yamenk
yamenk

Reputation: 51768

If you don't have a docker registry, what you need to do is save the image into a tarball, then upload it to the machine, then import the tarball back into a docker image.

On your local machine save the image into a tarball:

docker save --output image.tar <image>

Once you upload the tar to the target machine, you can import it back into a docker image using:

docker import image.tar <image-name>

From there on, the image will be on the machine and docker will not attempt to pull from a registry.

Upvotes: 5

Related Questions