Can Docker Autonomously Restart Containers and Commit Changes with New Image Tag?
I am using Docker for my deployment and as it stands I use Docker-Compose (.yml file) to launch ~6 containers simultaneously. Each image within the Compose file is locally found (no internet connection within deployment environment).
As it stands the steps my deployment takes are as follows:
- Run docker-compose up (launches 6 containers from local images such as image1:latest, image2:latest, etc. using the images with the “latest” tag)
- When exited/stopped, I have 6 stopped containers. Manually restart each of the six stopped containers (docker start xxx)
- Manually commit each re-started container (docker commit xxx)
- Manually re-tag each of the previous generation images incrementally (image1:latest -> image1:version1, image1:version2, etc.) and manually delete the image containing the “latest” tag
- Manually tag each of the committed containers (which are now images) with the “latest” tag (image1:latest)
This process is rather user-involved and our deployment requires the user involvement to only be run the “docker-compose up” command then shutting down/stopping Docker-Compose.
The required end goal is to have a script, or Docker, take care of these steps by itself and end up with different generations of images (image1:version1, image1:version2, image1:latest, etc.).
So, my question is, how would I go about creating a script (or have Docker do it) where the script (or Docker) can autonomously:
- Restart the stopped containers upon stopping/exiting of Docker-Compose
- Commit the restarted containers
- Re-tag the previous images with latest tags to an incremented version# (image1:version1, image1:version2, etc.) then delete the previous image1:latest image
- Tag the newly committed restarted containers (which are now images) with the “latest” tag
This is a rather lengthy and intensive question to answer, but I would appreciate any help with any of the steps required to accomplish my task. Thank you.
One Solution collect form web for “Can Docker Autonomously Restart Containers and Commit Changes with New Image Tag?”
The watchtower project tries to address this.
It auto restarts a running container when a base image is updated.
It is also intelligent so, for example, when in needs to restart a container that is linked to other containers, it does so without destroying the links.
I’ve never tried it but worth a shot!
Let us know how it goes. I’m gonna favourite this question as it sounds a great idea.
PS If watchtower proves a pain and you try to do this manually then …
is your friend since it gives you loads of info about containers and images. Allowing you to determine current status.