Updating docker images with minor changes using commits

I want to use caching / splitting docker images to save bandwidth, disk space and time spent.

Say:

  • I have a docker image for web applications installed and deployed to multiple docker hosts.
  • The docker image contains the source code of my web application.
  • I worked on the code and now I have a new version of the code.

How can I automate the creation of a new docker latch above the last image containing only the fix?

My goal is that to upload new images for docker hosts that have already uploaded the previous image, you only need a small bugfix error.

This is a question of my current reflection on this:

  • Most likely, I will return to docker commit to save the update on the image.
  • But how can I access the contents of the image?
  • And even then, how would I import my changes without cluttering up the original docker images with various tools (git and shell scripts) that have nothing to do with serving a web application?
  • I looked through the volumes to share the code with another docker who will take care of the upgrade. But volumes are not committed.

Thanks for understanding how to do this!

EDIT: using multiple Docker files seems like a different way of doing this, thanks http://jpetazzo.imtqy.com/2013/12/01/docker-python-pip-requirements/ for similar problems. It seems I will need to generate my docker files on the fly.

+6
source share
1 answer

Here's how to update an existing image using docker commit .

  • run the container with the image you want to change:

      docker run -t -i IMAGE /bin/bash 

    Note that you probably want to access some host / directory files to import changes to the container:

      docker run -t -i -v /host/location:/mnt/share IMAGE /bin/bash 

    Then close Ctrl-D or exit .

    If you want to automate this in a script, you will need to get the id container for the next step. And you will want to directly issue commands instead of invoking an interactive bash session:

      container_id=$(docker run -d -v /host/location:/mnt/share IMAGE /bin/bash -c " ## any bash code rsync -av --delete --exclude .git /mnt/share /my/app/ cd /my/app ./autogen.sh ") 
  • Commit the modified container file system as a new image:

      docker commit CONTAINER_ID IMAGE_NAME 

    Note. You can use the same IMAGE_NAME as the one you first started the container with. This will effectively update your image.

Additional issues:

  • Any modification made in the previous image should try to minimize the new layer created in the last image. The rules will probably depend on whether you use BTRFS (block level modifications will actually be in the "layer") or AUFS (file level changes). It would be best not to replace the whole source files with the same files (avoid cp -a , git checkout-index , favor rsync or git checkout ).

  • You will need to install some tools on your virtual machine so that you can do your updates (maybe git , rsync ...). But do not forget that you can also provide scripts (or even complete tools) thanks to the installed host volume.

  • The created image is not orthodox and does not come from the Dockerfile . You should probably restore a completely new image fairly regularly from the official Dockerfile . Or at least try to minimize layering by listing all your images in one official image.

+2
source

Source: https://habr.com/ru/post/975761/


All Articles