<h2id="executing_commands_before_and_after_updating">Executing commands before and after updating<aclass="headerlink"href="#executing_commands_before_and_after_updating"title="Permanent link">¶</a></h2>
<blockquote>
<p><strong>DO NOTE</strong>: Both commands are shell commands executed with <code>sh</code>, and therefore require the
<p><strong>DO NOTE</strong>: These are shell commands executed with <code>sh</code>, and therefore require the
container to provide the <code>sh</code> executable.</p>
</blockquote>
<p>It is possible to execute a <em>pre-update</em> command and a <em>post-update</em> command
<strong>inside</strong> every container updated by watchtower. The <em>pre-update</em> command is
executed before stopping the container, and the <em>post-update</em> command is
executed after restarting the container.</p>
<p>It is possible to execute <em>pre/post-check</em> and <em>pre/post-update</em> commands
<strong>inside</strong> every container updated by watchtower.</p>
<ul>
<li>The <em>pre-check</em> command is executed for each container prior to every update cycle.</li>
<li>The <em>pre-update</em> command is executed before stopping the container when an update is about to start.</li>
<li>The <em>post-update</em> command is executed after restarting the updated container</li>
<li>The <em>post-check</em> command is executed for each container post every update cycle.</li>
</ul>
<p>This feature is disabled by default. To enable it, you need to set the option
<code>--enable-lifecycle-hooks</code> on the command line, or set the environment variable
<code>WATCHTOWER_LIFECYCLE_HOOKS</code> to <code>true</code>.</p>