Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syncing docker images

Tags:

docker

I have 2 machines(separate hosts) running docker and I am using the same image on both the machines. How do I keep both the images in sync. For eg. suppose I make changes to the image in one of the hosts and want the changes to reflect in the other host as well. I can commit the image and copy the image over to the other host. Is there any other efficient way of doing this??

like image 892
vignesh1905 Avatar asked Jun 22 '26 23:06

vignesh1905


1 Answers

Some ways I can think of:

1. with a Docker registry

the workflow here is:

  • HOST A: docker commit, docker push
  • HOST B: docker pull

2. by saving the image to a .tar file

the workflow here is:

  • HOST A: docker save
  • HOST B: docker load

3. with a Dockerfile and by building the image again

the workflow here is:

  • provide a Dockerfile together with your code / files required
  • everytime your code has changed and you want to make a release, use docker build to create a new image.
  • from the hosts that you want to take the update, you will have to get the updated source code (maybe by using a version control software like Git), and then docker build the image

4. CI/CD pipeline

you can see a video here: docker.com/use-cases/cicd


Keep in mind that containers are considered to be ephemeral. This means that updating an image inside another host will then require:

  1. to stop and remove any old container (running with the outdated image)
  2. to run a new one (with the updated image)

I quote from: Best practices for writing Dockerfiles

General guidelines and recommendations

Containers should be ephemeral

The container produced by the image your Dockerfile defines should be as ephemeral as possible. By “ephemeral,” we mean that it can be stopped and destroyed and a new one built and put in place with an absolute minimum of set-up and configuration.

like image 93
tgogos Avatar answered Jun 25 '26 19:06

tgogos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!