diff mbox series

[3/9] docker-engine: add support for init processes

Message ID 20170920030210.19446-4-christian@paral.in
State RFC
Headers show
Series Upgrading Go to 1.9 and Docker to v2017.07 | expand

Commit Message

Christian Stewart Sept. 20, 2017, 3:02 a.m. UTC
When a docker container is run with the --init flag, the Docker engine
uses the docker-init binary as PID 1 inside the container. This is
necessary in may cases to avoid issues with signal handling, zombie
processes, and other quirks when running as PID 1.

The docker-init binary is backed by tini on default, but optionally can
be changed to docker-init by user preference.

Furthermore, this patch fixes the following Docker error:

  dockerd: level=warning msg="failed to retrieve docker-init version"

Signed-off-by: Christian Stewart <christian@paral.in>
---
 package/docker-engine/Config.in        | 26 ++++++++++++++++++++++++++
 package/docker-engine/docker-engine.mk | 11 +++++++++++
 2 files changed, 37 insertions(+)

Comments

Arnout Vandecappelle Sept. 21, 2017, 9:37 p.m. UTC | #1
On 20-09-17 05:02, Christian Stewart wrote:
> When a docker container is run with the --init flag, the Docker engine
> uses the docker-init binary as PID 1 inside the container. This is
> necessary in may cases to avoid issues with signal handling, zombie
> processes, and other quirks when running as PID 1.
> 
> The docker-init binary is backed by tini on default, but optionally can
> be changed to docker-init by user preference.

 OK, now I get the reason to build dumb-init statically: it actually comes from
outside the container, not inside. Honestly I don't understand why it takes an
executable from outside the container to run inside it, but OK.

> 
> Furthermore, this patch fixes the following Docker error:
> 
>   dockerd: level=warning msg="failed to retrieve docker-init version"

 On my Debian system there is no docker-init but I don't get this warning when
starting docker...


> 
> Signed-off-by: Christian Stewart <christian@paral.in>

Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

 Small nit below.

> ---
>  package/docker-engine/Config.in        | 26 ++++++++++++++++++++++++++
>  package/docker-engine/docker-engine.mk | 11 +++++++++++
>  2 files changed, 37 insertions(+)
> 
> diff --git a/package/docker-engine/Config.in b/package/docker-engine/Config.in
> index 05670a716e..7d9a87f7bb 100644
> --- a/package/docker-engine/Config.in
> +++ b/package/docker-engine/Config.in
> @@ -33,6 +33,32 @@ config BR2_PACKAGE_DOCKER_ENGINE_STATIC_CLIENT
>  
>  if BR2_PACKAGE_DOCKER_ENGINE_DAEMON
>  
> +choice
> +	bool "docker-init to use"
> +	default BR2_PACKAGE_DOCKER_ENGINE_INIT_TINI
> +	help
> +	  The docker engine uses a minimal init process as PID 1
> +	  inside containers. There are several implementations
> +	  of this init process.
> +
> +config BR2_PACKAGE_DOCKER_ENGINE_INIT_TINI
> +	bool "tini"
> +	select BR2_PACKAGE_TINI
> +	help
> +	  Use Tini as the container init process.
> +
> +	  https://github.com/krallin/tini

 Upstream URL is not needed here, only in the package itself.

 It might be useful to add some help text that indicates the difference between
tini and dumb-init.


 Regards,
 Arnout


> +
> +config BR2_PACKAGE_DOCKER_ENGINE_INIT_DUMB_INIT
> +	bool "dumb-init"
> +	select BR2_PACKAGE_DUMB_INIT
> +	help
> +	  Use dumb-init as the container init process.
> +
> +	  https://github.com/Yelp/dumb-init
> +
> +endchoice
> +
>  config BR2_PACKAGE_DOCKER_ENGINE_DRIVER_BTRFS
>  	bool "btrfs filesystem driver"
>  	depends on BR2_USE_MMU # btrfs-progs
> diff --git a/package/docker-engine/docker-engine.mk b/package/docker-engine/docker-engine.mk
> index 8928f072e7..a2776ed78c 100644
> --- a/package/docker-engine/docker-engine.mk
> +++ b/package/docker-engine/docker-engine.mk
> @@ -50,6 +50,13 @@ endif
>  ifeq ($(BR2_PACKAGE_DOCKER_ENGINE_DAEMON),y)
>  DOCKER_ENGINE_BUILD_TAGS += daemon
>  DOCKER_ENGINE_BUILD_TARGETS += dockerd
> +
> +ifeq ($(BR2_PACKAGE_DOCKER_ENGINE_INIT_DUMB_INIT),y)
> +DOCKER_ENGINE_INIT = dumb-init
> +else
> +DOCKER_ENGINE_INIT = tini
> +endif
> +
>  endif
>  
>  ifeq ($(BR2_PACKAGE_DOCKER_ENGINE_EXPERIMENTAL),y)
> @@ -119,6 +126,10 @@ define DOCKER_ENGINE_INSTALL_TARGET_CMDS
>  	$(foreach target,$(DOCKER_ENGINE_BUILD_TARGETS), \
>  		$(INSTALL) -D -m 0755 $(@D)/bin/$(target) $(TARGET_DIR)/usr/bin/$(target)
>  	)
> +
> +	$(if $(filter $(BR2_PACKAGE_DOCKER_ENGINE_DAEMON),y), \
> +		ln -fs $(DOCKER_ENGINE_INIT) $(TARGET_DIR)/usr/bin/docker-init
> +	)
>  endef
>  
>  $(eval $(generic-package))
>
Christian Stewart Sept. 21, 2017, 11:09 p.m. UTC | #2
Hi Arnout,

I marked this series as RFC on patchwork, just because there are a
couple of fixes I have applied and will respin after people are done
reviewing.

On Thu, Sep 21, 2017 at 10:37 PM, Arnout Vandecappelle <arnout@mind.be> wrote:
>  On my Debian system there is no docker-init but I don't get this warning when
> starting docker...

This is likely because Docker has changed since I wrote this patch
originally, which was against a version 4 versions ago around 6 months
ago.

>  Upstream URL is not needed here, only in the package itself.

Interesting, I put it there because for some reason I remember seeing
the upstream URL in the Config.in for other packages. Will remove.

>  It might be useful to add some help text that indicates the difference between
> tini and dumb-init.

Functionally there is none, but the actual implementations are just
slightly different by different authors. Tini is a bit newer but
backed by a less trusted source while dumb-init is old and backed by
Yelp. For some reason Tini is used by the docker official
distribution.

Best,
Christian
diff mbox series

Patch

diff --git a/package/docker-engine/Config.in b/package/docker-engine/Config.in
index 05670a716e..7d9a87f7bb 100644
--- a/package/docker-engine/Config.in
+++ b/package/docker-engine/Config.in
@@ -33,6 +33,32 @@  config BR2_PACKAGE_DOCKER_ENGINE_STATIC_CLIENT
 
 if BR2_PACKAGE_DOCKER_ENGINE_DAEMON
 
+choice
+	bool "docker-init to use"
+	default BR2_PACKAGE_DOCKER_ENGINE_INIT_TINI
+	help
+	  The docker engine uses a minimal init process as PID 1
+	  inside containers. There are several implementations
+	  of this init process.
+
+config BR2_PACKAGE_DOCKER_ENGINE_INIT_TINI
+	bool "tini"
+	select BR2_PACKAGE_TINI
+	help
+	  Use Tini as the container init process.
+
+	  https://github.com/krallin/tini
+
+config BR2_PACKAGE_DOCKER_ENGINE_INIT_DUMB_INIT
+	bool "dumb-init"
+	select BR2_PACKAGE_DUMB_INIT
+	help
+	  Use dumb-init as the container init process.
+
+	  https://github.com/Yelp/dumb-init
+
+endchoice
+
 config BR2_PACKAGE_DOCKER_ENGINE_DRIVER_BTRFS
 	bool "btrfs filesystem driver"
 	depends on BR2_USE_MMU # btrfs-progs
diff --git a/package/docker-engine/docker-engine.mk b/package/docker-engine/docker-engine.mk
index 8928f072e7..a2776ed78c 100644
--- a/package/docker-engine/docker-engine.mk
+++ b/package/docker-engine/docker-engine.mk
@@ -50,6 +50,13 @@  endif
 ifeq ($(BR2_PACKAGE_DOCKER_ENGINE_DAEMON),y)
 DOCKER_ENGINE_BUILD_TAGS += daemon
 DOCKER_ENGINE_BUILD_TARGETS += dockerd
+
+ifeq ($(BR2_PACKAGE_DOCKER_ENGINE_INIT_DUMB_INIT),y)
+DOCKER_ENGINE_INIT = dumb-init
+else
+DOCKER_ENGINE_INIT = tini
+endif
+
 endif
 
 ifeq ($(BR2_PACKAGE_DOCKER_ENGINE_EXPERIMENTAL),y)
@@ -119,6 +126,10 @@  define DOCKER_ENGINE_INSTALL_TARGET_CMDS
 	$(foreach target,$(DOCKER_ENGINE_BUILD_TARGETS), \
 		$(INSTALL) -D -m 0755 $(@D)/bin/$(target) $(TARGET_DIR)/usr/bin/$(target)
 	)
+
+	$(if $(filter $(BR2_PACKAGE_DOCKER_ENGINE_DAEMON),y), \
+		ln -fs $(DOCKER_ENGINE_INIT) $(TARGET_DIR)/usr/bin/docker-init
+	)
 endef
 
 $(eval $(generic-package))