Please stop me if I'm talking nonsense. I'm trying to figure out if OpenRC can be used as an alternative to supervisord. It comes already shipped with Alpine, it allows to start services and respawn them, and I saw a few notes that it also allows to send logs to stdout. That's kind of everything supervisord is doing in a simple case, right? But OpenRC doesn't require python and other dependencies that quadruple the final image size.
I've tried this:
$ docker run -ti alpine sh
/ # /sbin/init
init: must be run as PID 1
/ # /sbin/openrc
* Caching service dependencies ... [ ok ]
/ # apk --update add nginx
…
/ # rc-service nginx start
* Caching service dependencies ... [ ok ]
* You are attempting to run an openrc service on a
* system which openrc did not boot.
* You may be inside a chroot or you may have used
* another initialization system to boot this system.
* In this situation, you will get unpredictable results!
* If you really want to do this, issue the following command:
* touch /run/openrc/softlevel
* ERROR: fsck failed to start
* ERROR: cannot start root as fsck would not start
* ERROR: cannot start localmount as fsck would not start
* ERROR: cannot start networking as fsck would not start
* ERROR: cannot start nginx as fsck would not start
/ # touch /run/openrc/softlevel
/ # rc-service nginx start
* Checking local filesystems ... [ ok ]
* Remounting filesystems ... [ ok ]
* Mounting local filesystems ... [ ok ]
* Starting networking ...
awk: /etc/network/interfaces: No such file or directory
* ERROR: networking failed to start
* ERROR: cannot start nginx as networking would not start
Then I tried to do it this, and it just goes into infinite loop:
$ docker run -ti alpine /sbin/init
OpenRC 0.15.1.c4bc9ea is starting up Linux 4.0.3-boot2docker (x86_64)
* /proc is already mounted
* Mounting /run ...
mount: permission denied (are you root?)
* Unable to mount tmpfs on /run.
* Can't continue.
* Caching service dependencies ... [ ok ]
can't open /dev/tty1: No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty5: No such file or directory
can't open /dev/tty6: No such file or directory
can't open /dev/tty1: No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty5: No such file or directory
can't open /dev/tty6: No such file or directory
Is there a way to use OpenRC instead of supervisord inside the container?
OpenRC won't work in a container where it is not pid 1. See https://github.com/gliderlabs/docker-alpine/issues/26 for similar question. If you really do want an init system, look at the custom one built into the phusion base image. Though, we generally build containers as single processes rather than fat images.
Hey Andy, thanks for response, but it doesn't answer the question or sheds any light. I've figured out that it won't work where it's not PID 1 from the very first message init: must be run as PID 1. Phusion base image is essentially a Ubuntu and has nothing todo with Alpine. I'm aware of other alternatives from this and a few other topics.
From your response I get that OpenRC is not something that used at all inside the container. Is there any reason it's there then or is it part of Alpine that can't be easily removed? In other words why not make the image even lighter without OpenRC if it doesn't provide any value?
If it's something that can easily be removed, we should. Feel free to submit a PR.
Just to confirm, we don't support the use of traditional init systems for minimal containers built with Alpine. They make too many assumptions about the system running as a full Linux system, not as a minimal container.
Understood, I saw it as one of a very few things available and thought that's for a reason. Thanks for clearing this up.
There is already a pull request open for removing OpenRC and other unneeded bits. I'd follow https://github.com/gliderlabs/docker-alpine/pull/32.
:+1:
To be able to use openrc inside a alpine container, you may try using --privileged attribute to run it.
This is a comparable issue with systemd also and a known docker issue explained here: https://docs.docker.com/v1.2/reference/commandline/cli/
I know I might be way late but I was able to get openrc to work inside docker:
https://github.com/neeravkumar/dockerfiles/tree/master/alpine-openrc
680f8a49b903:~# rc-status
Runlevel: default
sshd [ started ]
lighttpd [ started ]
mariadb [ started ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
root [ started ]
localmount [ started ]
fsck [ started ]
Dynamic Runlevel: manual
680f8a49b903:~# ps auxwww
PID USER TIME COMMAND
1 root 0:00 init
148 root 0:00 /usr/sbin/sshd
349 mysql 0:00 /usr/bin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --pid-file=/run/mysqld/mysqld.pid --socket=/run/mysqld/mysqld.sock --port=3306
350 root 0:00 logger -t mysqld -p daemon.error
407 lighttpd 0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
409 lighttpd 0:00 /usr/bin/php-cgi
412 lighttpd 0:00 /usr/bin/php-cgi
413 lighttpd 0:00 /usr/bin/php-cgi
414 lighttpd 0:00 /usr/bin/php-cgi
415 lighttpd 0:00 /usr/bin/php-cgi
416 lighttpd 0:00 /usr/bin/php-cgi
417 lighttpd 0:00 /usr/bin/php-cgi
418 lighttpd 0:00 /usr/bin/php-cgi
419 root 0:00 sshd: alex [priv]
421 alex 0:00 sshd: alex@pts/0
422 alex 0:00 -sh
423 root 0:00 -ash
425 root 0:00 ps auxwww
@acoul was that built on top of @neeravkumar 's alpine-openrc image? Also, could you provide an example Dockerfile?
sorry, can't recall.
I mainly use alpine linux on usb flash/keys for old 32bit laptops
Most helpful comment
I know I might be way late but I was able to get openrc to work inside docker:
https://github.com/neeravkumar/dockerfiles/tree/master/alpine-openrc