Search code examples
dockerdebianinitmolecule

Debian image - /sbin/init not found


I am trying to start a Debian image with the /sbin/init process for ansible role testing via molecule.

Yes, I am aware, that one should not start /sbin/init in a container unless you really have a use case for doing so. With molecule I can test my ansible roles in a docker container. As such I need /sbin/init running.

When I execute

docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro debian:9 /sbin/init

docker: Error response from daemon: OCI runtime create failed: container_linux.go:346:
starting container process caused "exec: \"/sbin/init\": stat /sbin/init: no such file 
or directory": unknown.

However, with debian:8 it works just fine.

docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro debian:8 /sbin/init

works like a charm.

Has Debian switched to a new boot process? What changed?


Solution

  • Turns out Debian has removed the init package from their docker images starting with debian:9 and newer.

    That is great since it helps all of us to fail early/fast. We really should not start /sbin/init unless we have a use-case for doing so - and believe me, most of the time we do not.

    So what to do if we really have a use-case in which we need to run /sbin/init?

    Well, we can install it via

    apt-get install -y init
    

    If you need a Dockerfile for that

    FROM debian:9
    
    RUN apt-get update && apt-get install -y init && apt-get clean all