0

How do you run systemd in a Docker managed plugin? With a normal container I can run centos/systemd and run an Apache server using their example Dockerfile

FROM centos/systemd
RUN yum -y install httpd; yum clean all; systemctl enable httpd.service
EXPOSE 80
CMD ["/usr/sbin/init"]

And running it as follows

docker build --rm --no-cache -t httpd .
docker run --privileged --name httpd -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 -d  httpd

However, when I try to make a managed plugin, there are some issues with the cgroups

I've tried putting in the config.json

    {
        "destination": "/sys/fs/cgroup",
        "source": "/sys/fs/cgroup",
        "type": "bind",
        "options": [
            "bind",
            "ro",
            "private"
        ]
    }

    {
        "destination": "/sys/fs/cgroup",
        "source": "/sys/fs/cgroup",
        "type": "bind",
        "options": [
            "bind",
            "ro",
            "rprivate"
        ]
    }

    {
        "destination": "/sys/fs/cgroup",
        "source": "/sys/fs/cgroup",
        "type": "bind",
        "options": [
            "rbind",
            "ro",
            "rprivate"
        ]
    }

I also tried the following which damages the host's cgroup which may require a hard reboot to recover.

    {
        "destination": "/sys/fs/cgroup/systemd",
        "source": "/sys/fs/cgroup/systemd",
        "type": "bind",
        "options": [
            "bind",
            "ro",
            "private"
        ]
    }

    {
        "destination": "/sys/fs/cgroup",
        "source": "/sys/fs/cgroup",
        "type": "bind",
        "options": [
            "bind",
            "ro",
            "private"
        ]
    }

It looks to be something to do with how opencontainer and moby interact https://github.com/moby/moby/issues/36861

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

2 Answers2

0

This is how I did it on my https://github.com/trajano/docker-volume-plugins/tree/master/centos-mounted-volume-plugin

The key thing to do is preserve the /run/docker/plugins before systemd gets started and wipes the /run folder. Then make sure you create the socket in the new folder.

mkdir -p /dockerplugins
if [ -e /run/docker/plugins ]
then
  mount --bind /run/docker/plugins /dockerplugins
fi

The other thing is that Docker managed plugins add an implicit /sys/fs/cgroup AFTER the defined mounts in config so creating a readonly mount will not work unless it was rebound before starting up systemd.

mount --rbind /hostcgroup /sys/fs/cgroup

With the mount defined in config.json as

{
        "destination": "/hostcgroup",
        "source": "/sys/fs/cgroup",
        "type": "bind",
        "options": [
            "bind",
            "ro",
            "private"
        ]
}

Creating the socket needs to be customized since the plugin helpers write to /run/docker/plugins

l, err := sockets.NewUnixSocket("/dockerplugins/osmounted.sock", 0)
if err != nil {
    log.Fatal(err)
}
h.Serve(l)

The following shows the process above on how I achieved it on my plugin

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
-1

You can run httpd in a centos container without systemd - atleast to the tests with the docker-systemctl-replacement script.

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19