Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker "Couldn't find an alternative telinit implementation to spawn"

I'm a MAC user and installed docker inside a VM "ubuntu 14.04". (I installed everything manually, NOT using docker toolbox)

The problem is when I start specific container (other containers run normally), it gives me this weird error message "Couldn't find an alternative telinit implementation to spawn".

here is the Dockerfile I used to build the image:

FROM diegomarangoni/hhvm:cli

# install php composer.
# It needs git and the PHP zip extension
# zlib1g-dev is needed to compile the PHP zip extension
# openssh-client provides ssh-keyscan
RUN apt-get update \
    && apt-get install --assume-yes --no-install-recommends curl git zlib1g-dev openssh-client \
    && apt-get clean && rm -r /var/lib/apt/lists/* \
    && curl -sS https://getcomposer.org/installer -o installer \
    && hhvm -v ResourceLimit.SocketDefaultTimeout=30 -v Http.SlowQueryThreshold=30000 installer \
    && mv composer.phar /usr/local/bin/composer \
    && rm installer

WORKDIR /home/assert/scripts

COPY scripts/composer.json /home/assert/
COPY scripts /home/assert/scripts

RUN hhvm -v ResourceLimit.SocketDefaultTimeout=30 -v Http.SlowQueryThreshold=30000 -v Eval.Jit=false \
    /usr/local/bin/composer install

# Run the assert container web server
CMD ["hhvm", "-v", "Eval.Jit=false", "/home/assert/scripts/vendor/bin/phpunit", "/home/assert/scripts/tests", "--configuration", "/home/assert/scripts/tests/phpunit.xml"]

# keep it running
CMD /sbin/init

and I start it using command:

docker run <CONTAINER>

Thanks in advance,

like image 633
Mohamed Kamal Avatar asked Apr 11 '16 09:04

Mohamed Kamal


1 Answers

Could be a few things going on here depending on your versions. Have you tried Dan Walsh's older post? http://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/

In older versions this likely is because of two requirements Docker needs to do systemd:

  1. Need to run with --privileged
  2. Need to include volume /sys/fs/cgroup

If you strace, you may find:

ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
lstat("/run/systemd/system/", 0x7fffa5b4e300) = -1 ENOENT (No such file or directory)
execve("/lib/sysvinit/telinit", ["/usr/sbin/init"], [/* 8 vars */]) = -1 ENOENT (No such file or directory)
writev(2, [{"Couldn't find an alternative tel"..., 61}, {"\n", 1}], 2Couldn't find an alternative telinit implementation to spawn.
) = 62
exit_group(1)                           = ?
+++ exited with 1 +++

Note that somewhere along the line "init" and "telinit" became common symlinks which is frustrating. Even more confusing, this is a Red Hat-based distro (CentOS) whose legacy fallback should be Upstart, not SystemV. In any case, it's helpful to just call it what it is: use systemd binary directly, NOT /usr/sbin/init hoping it's a symlink to systemd binary.

In modern versions I've tried playing with symlinks to get things right but find the best way to go is actually just changing the run command a bit.

docker run -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro [image] /bin/bash

Once you're that far it's perfectly alright to run systemd directly:

/usr/lib/systemd/systemd --system --unit=basic.target

This is how I see it with systemd version below:

Name        : systemd
Arch        : x86_64
Version     : 219
Release     : 19.el7_2.12
Size        : 5.1 M

Hope this helps. Lots of older documents out there and changing systemd specs. JohnnyB

like image 106
BoeroBoy Avatar answered Oct 02 '22 21:10

BoeroBoy