moby/daemon
Thomas Leonard b6c7becbfe
Add support for user-defined healthchecks
This PR adds support for user-defined health-check probes for Docker
containers. It adds a `HEALTHCHECK` instruction to the Dockerfile syntax plus
some corresponding "docker run" options. It can be used with a restart policy
to automatically restart a container if the check fails.

The `HEALTHCHECK` instruction has two forms:

* `HEALTHCHECK [OPTIONS] CMD command` (check container health by running a command inside the container)
* `HEALTHCHECK NONE` (disable any healthcheck inherited from the base image)

The `HEALTHCHECK` instruction tells Docker how to test a container to check that
it is still working. This can detect cases such as a web server that is stuck in
an infinite loop and unable to handle new connections, even though the server
process is still running.

When a container has a healthcheck specified, it has a _health status_ in
addition to its normal status. This status is initially `starting`. Whenever a
health check passes, it becomes `healthy` (whatever state it was previously in).
After a certain number of consecutive failures, it becomes `unhealthy`.

The options that can appear before `CMD` are:

* `--interval=DURATION` (default: `30s`)
* `--timeout=DURATION` (default: `30s`)
* `--retries=N` (default: `1`)

The health check will first run **interval** seconds after the container is
started, and then again **interval** seconds after each previous check completes.

If a single run of the check takes longer than **timeout** seconds then the check
is considered to have failed.

It takes **retries** consecutive failures of the health check for the container
to be considered `unhealthy`.

There can only be one `HEALTHCHECK` instruction in a Dockerfile. If you list
more than one then only the last `HEALTHCHECK` will take effect.

The command after the `CMD` keyword can be either a shell command (e.g. `HEALTHCHECK
CMD /bin/check-running`) or an _exec_ array (as with other Dockerfile commands;
see e.g. `ENTRYPOINT` for details).

The command's exit status indicates the health status of the container.
The possible values are:

- 0: success - the container is healthy and ready for use
- 1: unhealthy - the container is not working correctly
- 2: starting - the container is not ready for use yet, but is working correctly

If the probe returns 2 ("starting") when the container has already moved out of the
"starting" state then it is treated as "unhealthy" instead.

For example, to check every five minutes or so that a web-server is able to
serve the site's main page within three seconds:

    HEALTHCHECK --interval=5m --timeout=3s \
      CMD curl -f http://localhost/ || exit 1

To help debug failing probes, any output text (UTF-8 encoded) that the command writes
on stdout or stderr will be stored in the health status and can be queried with
`docker inspect`. Such output should be kept short (only the first 4096 bytes
are stored currently).

When the health status of a container changes, a `health_status` event is
generated with the new status. The health status is also displayed in the
`docker ps` output.

Signed-off-by: Thomas Leonard <thomas.leonard@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2016-06-02 23:58:34 +02:00
..
caps Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
events Add filter for events emitted by docker daemon 2016-05-23 19:00:47 -07:00
exec Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
graphdriver Merge pull request #23121 from unclejack/disallow_ecryptfs_aufs 2016-06-02 12:54:43 +02:00
links Replace usage of pkg/nat with go-connections/nat. 2015-12-22 13:31:46 -05:00
logger Fix the comment for daemon/logger.Copier 2016-06-02 13:10:51 +09:00
network Add "driver" filter for network ls 2016-04-29 16:22:26 +02:00
apparmor_default.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
apparmor_default_unsupported.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
archive.go Windows: docker cp consistent paths 2016-05-06 16:08:53 -07:00
archive_unix.go Windows: docker cp consistent paths 2016-05-06 16:08:53 -07:00
archive_windows.go Windows: Remove TP4 support from main code 2016-04-06 12:12:20 -07:00
attach.go Let client print error when speicify wrong detach keys 2016-04-04 15:35:55 +08:00
auth.go Moving some more methods away from daemon.go 2016-05-27 11:32:26 +02:00
changes.go Move some container related methods and structs to smaller files 2016-05-24 21:31:15 +02:00
commit.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
config.go Fix some mistakes in dockerd.md 2016-05-19 20:41:37 +08:00
config_experimental.go Move userns support out of experimental into master 2016-01-08 15:06:22 -05:00
config_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
config_stub.go Add user namespace enable flag --userns-remap in experimental build 2015-10-09 20:50:05 -04:00
config_test.go add validating configs from configuration file 2016-03-16 00:05:52 +08:00
config_unix.go Fix some mistakes in dockerd.md 2016-05-19 20:41:37 +08:00
config_windows.go Windows: bridgeConfig rework 2016-03-28 12:24:01 -07:00
container.go Moving some more methods away from daemon.go 2016-05-27 11:32:26 +02:00
container_operations.go Update port info on network connect/disconnect 2016-05-25 17:02:50 -07:00
container_operations_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
container_operations_unix.go Add support for --pid=container:<id> 2016-05-17 13:49:05 -04:00
container_operations_windows.go Merge pull request #21809 from Microsoft/jjh/tp4removal 2016-04-06 14:11:33 -07:00
create.go Merge pull request #23019 from vdemeester/more-daemon-horn-moving 2016-05-28 22:07:31 -07:00
create_unix.go Merge pull request #21270 from ehazlett/resource-labels 2016-03-22 15:12:33 -04:00
create_windows.go Windows: Default isolation and workdir 2016-05-26 13:24:22 -07:00
daemon.go Merge pull request #23019 from vdemeester/more-daemon-horn-moving 2016-05-28 22:07:31 -07:00
daemon_experimental.go Move userns support out of experimental into master 2016-01-08 15:06:22 -05:00
daemon_linux.go Fix container mount cleanup issues 2016-03-30 17:25:49 -07:00
daemon_linux_test.go Fix container mount cleanup issues 2016-03-30 17:25:49 -07:00
daemon_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
daemon_stub.go Move userns support out of experimental into master 2016-01-08 15:06:22 -05:00
daemon_test.go Wait for discovery on container start error 2016-05-11 09:49:51 -04:00
daemon_unix.go Multiple fixes for SELinux labels. 2016-05-25 16:11:02 -04:00
daemon_unix_test.go Consolidate security options to use = as separator. 2016-03-17 13:34:42 -04:00
daemon_unsupported.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
daemon_windows.go Merge pull request #22774 from Microsoft/jjh/client 2016-05-23 11:29:50 -07:00
debugtrap_unix.go Windows: Win32 event for sigusr1 linux equivalence 2015-07-06 18:58:53 -07:00
debugtrap_unsupported.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
debugtrap_windows.go Windows: psignal alias not required 2016-03-27 17:23:34 -07:00
delete.go Merge pull request #21802 from tiborvass/carry-21716 2016-04-06 15:21:38 -04:00
delete_test.go Remove static errors from errors package. 2016-02-26 15:49:09 -05:00
discovery.go Wait for discovery on container start error 2016-05-11 09:49:51 -04:00
discovery_test.go Fix minor vet warnings 2016-02-03 10:43:01 -08:00
errors.go Remove static errors from errors package. 2016-02-26 15:49:09 -05:00
events.go Add filter for events emitted by docker daemon 2016-05-23 19:00:47 -07:00
events_test.go Add the possibility to log event with specific attributes 2016-01-17 12:14:01 +01:00
exec.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
exec_linux.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
exec_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
exec_windows.go Windows: escape entrypoint before passing to libcontainerd 2016-03-30 12:59:50 -07:00
export.go Remove static errors from errors package. 2016-02-26 15:49:09 -05:00
health.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
health_test.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
image.go Move some image related methods & struct to smaller files 2016-05-21 22:36:11 +02:00
image_delete.go Remove static errors from errors package. 2016-02-26 15:49:09 -05:00
image_exporter.go Move some image related methods & struct to smaller files 2016-05-21 22:36:11 +02:00
image_history.go Move some image related methods & struct to smaller files 2016-05-21 22:36:11 +02:00
image_inspect.go Move some image related methods & struct to smaller files 2016-05-21 22:36:11 +02:00
image_pull.go Remove reference package dependency from the api. 2016-04-07 15:01:23 -07:00
image_push.go Remove reference package dependency from the api. 2016-04-07 15:01:23 -07:00
image_tag.go Remove reference package dependency from the api. 2016-04-07 15:01:23 -07:00
images.go Add before and since filter to images 2016-05-25 13:49:10 +02:00
import.go Remove reference package dependency from the api. 2016-04-07 15:01:23 -07:00
info.go handle error when getting hostname in info api 2016-05-07 08:51:52 +08:00
inspect.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
inspect_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
inspect_unix.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
inspect_windows.go Windows libcontainerd implementation 2016-03-18 13:38:41 -07:00
kill.go Move some container related methods and structs to smaller files 2016-05-24 21:31:15 +02:00
links.go Add migration from sqlite links back to hostConfig 2016-01-11 11:31:29 -05:00
links_test.go Extract container store from the daemon. 2016-01-19 13:21:41 -05:00
list.go Optimize docker ps when name/id filters in use 2016-05-30 17:43:55 -04:00
list_unix.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
list_windows.go Move Container to its own package. 2015-12-03 17:39:49 +01:00
logdrivers_linux.go daemon/logger: Add logging driver for Google Cloud Logging 2016-03-01 08:06:10 -08:00
logdrivers_windows.go Windows: Add ETW logging driver plug-in 2016-02-16 13:24:49 -08:00
logs.go Remove the logger.Message ContainerID field 2016-05-31 16:41:29 -04:00
monitor.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
monitor_linux.go Adding postRunProcessing infrastructure for hanlding Windows Update. 2016-04-06 14:03:05 -07:00
monitor_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
monitor_windows.go Adding servicing update to postRunProcessing for Windows containers. 2016-04-25 12:16:26 -07:00
mounts.go Remove static errors from errors package. 2016-02-26 15:49:09 -05:00
names.go Moving some more methods away from daemon.go 2016-05-27 11:32:26 +02:00
network.go Docker changes for libnetwork vendoring b66c038 2016-05-16 15:04:01 -07:00
oci_linux.go Inconsistent --tmpfs behavior 2016-05-26 19:28:18 -07:00
oci_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
oci_windows.go Windows: Use image version, not OS version for TTY fixup 2016-05-25 12:22:52 -07:00
pause.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
rename.go Embedded DNS problem after renaming container. Step2:change in docker/daemon side and add integration test 2016-05-26 12:59:44 +08:00
resize.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
restart.go Remove static errors from errors package. 2016-02-26 15:49:09 -05:00
search.go Validate filter values before calling registry. 2016-05-27 11:13:12 +02:00
search_test.go Add Unit test to daemon.SearchRegistryForImages… 2016-05-24 11:07:11 +02:00
seccomp_disabled.go Error out if user tries to specify a custom seccomp profile on system that does not support it 2016-05-31 17:52:40 +01:00
seccomp_linux.go Align default seccomp profile with selected capabilities 2016-05-11 09:30:23 +01:00
selinux_linux.go Rename daemon/utils_*.go to selinux 2015-11-12 15:48:41 -08:00
selinux_unsupported.go Rename daemon/utils_*.go to selinux 2015-11-12 15:48:41 -08:00
start.go inherit the daemon log options when creating containers 2016-05-02 23:04:04 +08:00
stats.go cleanup: clean up commented code in daemon/stats.go 2016-06-02 14:39:12 +08:00
stats_collector_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
stats_collector_unix.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
stats_collector_windows.go Move Container to its own package. 2015-12-03 17:39:49 +01:00
stop.go Add support for user-defined healthchecks 2016-06-02 23:58:34 +02:00
top_unix.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
top_windows.go Windows: Minimal docker top implementation 2016-03-20 16:45:53 -07:00
unpause.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
update.go Remove WaitRunning 2016-04-27 11:36:47 +08:00
update_linux.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
update_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
update_windows.go Windows libcontainerd implementation 2016-03-18 13:38:41 -07:00
volumes.go Fix docker create with duplicate volume failed to remove 2016-05-06 22:48:02 -04:00
volumes_unit_test.go reorder imports with goimports 2015-12-16 16:50:25 +01:00
volumes_unix.go Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
volumes_windows.go Remove unneeded references to execDriver 2016-03-21 13:06:08 -07:00
wait.go Rename Daemon.Get to Daemon.GetContainer. 2015-12-11 12:39:28 -05:00