Repository: containrrr/watchtower

Issue #183: Executing commands before stopping containers and after restarting them
Created: 2018-03-25T18:41:40Z
Hello,
I would like to use Watchtower to automatically update some database containers. However, these containers (running the official postgres image) cannot be simply updated by stopping them, pulling the new image, and restarting the containers. Indeed if the update happened between major versions, the data needs to be migrated. One way to do this is to dump the data from the old container, and import the dump with the updated containers.
I do not think that there is now a simple way to do this using Watchtower. However I was thinking that a mechanism could be added to watchtower in order to execute this kind of actions. It could take the form of a pair of pre/post command lines that should be executed before stopping the container, and after restarting it. A different pair could be specified for each container using labels, for instance.
I would like to investigate the feasibility of this features, and implement it. But I would like to know first if such a feature would be welcomed, or if there is some issues with the idea itself.
Best regards,
Alexandre Menif

Duplicate issue #286: Execute command inside container after update
Created: 2019-04-24T09:54:26Z
Is your feature request related to a problem? Please describe.
The GitLab CE docker container does not include sendmail. You can manually install it, but when watchtower updates gitlab/gitlab-ce:latest, it is gone again.
Describe the solution you'd like
It would be convenient if a configurable command or script could be run on a specific container that has watchtower enabled. In this specific case, I need to execute the following after every update:
docker exec -t gitlab_gitlab_1 apt update
docker exec -t gitlab_gitlab_1 apt install -y sendmail
docker exec -t gitlab_gitlab_1 service sendmail start

Describe alternatives you've considered
I'm running a cron-job that checks every now and then if the sendmail package is installed, and if not, install it. However there is a delay between the watchtower run and the cron task. Also, this is external and needs to be memorized by the sysadmin. If you move docker-compose.yml to a different directory, the container name changes after reboot. The cron job will not find the container.
Additional context
This is partially similar to #183. However, this issue does not require a script to run externally, e.g. access external/local volumes, nor require pre-update steps. We would just need a facility to execute some simple commands on the container.

Closing comment (2019-04-25T19:23:58Z): @simskij Thanks, that's what I was trying to say. Building a custom container with sendmail is what I'd do, even if it's just adding a single argument to the Docker build file.
@Redsandro As far as I understand the philosophy behind Docker, containers shouldn't be used like virtual machines. We don't install packages in a container, we build containers that already include those packages (which can easily be automated). Running a package manager within a container defeats (from my point of view) the whole use case of a container.
On the other hand … I don't feel comfortable with closing #197. I don't think it's a valid use case (neither the problem here nor the problem described in #197), but if someone provides a PR, sure, why not? If someone really has to execute a command after a container upgrade (or before, and I'm sure somewhere there's a valid use case where this functionality is absolutely necessary), then why shouldn't watchtower include that?
I'd leave this issue open until PR #197 gets merged (or, as alternative, mark this as duplicate of #183).