1

I have a container that runs systemd, the setup instructions followed can be found at

Now I have a script install.sh which I need to run in the build phase over the base image created above. The problem is that the install.sh is systemd aware.

So what is the easiest way to have systemd's init run that install.sh, what I want is something like

buildah run $ctr -- sh /tmp/install.sh

But this will not run install.sh under systemd, as I require.

Evan Carroll
  • 28,578
  • 45
  • 164
  • 290

1 Answers1

0

I used to build the same systemd image with buildah and tried to execute a simple script and it works fine ; maybe i am missing something :

 buildah run -t -v /sys/fs/cgroup:/sys/fs/cgroup:ro  onbuild-image-working-container-2  sh -c 'cat /tmp/install.sh'
--> #!/bin/bash
--> echo lol

buildah run -t -v /sys/fs/cgroup:/sys/fs/cgroup:ro  onbuild-image-working-container-2  sh -c 'chmod 777 /tmp/install.sh && /tmp/install.sh'
--> lol

OUTPUT : lol

SINCE your last comment: Using here docker

BUILDAH is meant for building OCI images, so if you are using in parallel podman or docker just use push the image to a local registry using buildah after building systemd-image from Dockerfile and mount /sys/fs/cgroup on /sys/fs/cgroup with read-only options so it wont override your systemd cgroups :

buildah bud --format=docker -f Dockerfile -t onbuild-image <path_to_DockerFile>
docker run -d -p 5000:5000 --restart=always --name registry registry:2
buildah push --tls-verify=false onbuild-image docker://localhost:5000/systemd-centos:latest
docker pull localhost:5000/systemd-centos:latest
ctr1="$(docker run -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 8000:80 localhost:5000/systemd-centos)"
docker exec -it $ctr1 'systemctl'
Reda Salih
  • 1,724
  • 4
  • 9
  • Because these are just commands you're running. You're not actually making use of systemd, and you're not starting init. Try making a call to systemctl for example, on your host machine and in your container. One of them works, one of them doesn't. – Evan Carroll Nov 14 '20 at 06:37
  • Check the edit i maid. It's functional and tested – Reda Salih Nov 15 '20 at 00:16
  • I'm not using docker anywhere. In your example though what's happening is you're using special images and running init manually. Then execing what you want to run. That works, but that's not what I want. I want to run the image and have init spawn the desired process. – Evan Carroll Nov 17 '20 at 15:58
  • So buildah is not meant for that. – Reda Salih Nov 17 '20 at 16:07