systemctl status during podman build
Hi, question that I don't understand, I'd be grateful for explaining or reference to what I should read to get it. Why during Podman build command `systemctl enable httpd` is working but `systemctl status httpd` is not working? Dockerfile not working: ``` FROM registry.access.redhat.com/ubi8/ubi-init RUN yum -y install httpd; yum clean all; RUN systemctl enable httpd; RUN systemctl status httpd; ``` output of `podman build .`: ``` STEP 2/4: RUN yum -y install httpd; yum clean all; STEP 1/4: FROM registry.access.redhat.com/ubi8/ubi-init Build output: --> 02f6efde590f --> Using cache 02f6efde590f9fec989c04a01a661d2650b462aeb8e61ad3c0e00aae1b16b1ef --> Using cache 4f85f566fdee4fd8f5e8058dbf39c5ec9be95a4879d4d9a8c7a77f5b9cadf8a7 STEP 3/4: RUN systemctl enable httpd; STEP 4/4: RUN systemctl status httpd; --> 4f85f566fdee System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down ``` But! If I exec into the container when he is running both of them are working. Working Dockerfile: ``` FROM registry.access.redhat.com/ubi8/ubi-init RUN yum -y install httpd; yum clean all; RUN systemctl enable httpd; ``` command: `podman build . -t x ; podman run -d --name x x ; podman exec -ti x bash -c "systemctl status httpd"` runs with success ``` STEP 1/3: FROM registry.access.redhat.com/ubi8/ubi-init STEP 2/3: RUN yum -y install httpd; yum clean all; --> Using cache 02f6efde590f9fec989c04a01a661d2650b462aeb8e61ad3c0e00aae1b16b1ef --> 02f6efde590f STEP 3/3: RUN systemctl enable httpd; --> Using cache 4f85f566fdee4fd8f5e8058dbf39c5ec9be95a4879d4d9a8c7a77f5b9cadf8a7 COMMIT x --> 4f85f566fdee Successfully tagged localhost/x:latest 4f85f566fdee4fd8f5e8058dbf39c5ec9be95a4879d4d9a8c7a77f5b9cadf8a7 214ee56866fc0e7d71b6d152749bdcb65d4e5aadb95dafcebb5661ee20770619 [root@214ee56866fc /]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2023-09-19 20:07:22 UTC; 6s ago Docs: man:httpd.service(8) Main PID: 30 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 1638) Memory: 22.3M CGroup: /system.slice/httpd.service ├─30 /usr/sbin/httpd -DFOREGROUND ├─34 /usr/sbin/httpd -DFOREGROUND ├─35 /usr/sbin/httpd -DFOREGROUND ├─36 /usr/sbin/httpd -DFOREGROUND └─37 /usr/sbin/httpd -DFOREGROUND versions: podman version 4.6.2 on macos ventura 13.5.2
Yeah this is annoying, but the environment during a build is typically a lot different that when running. During a build, there's basically no way to predict what podman arguments will be used to run the image, volumes mounted, user-namespace stuff, etc. I'm not a systemd expert, but I believe you can "mimic" the effects of `systemctl enable...` with some symlinking. Looking at my Fedora system (your case will probably vary a little), I think what you want in your Containerfile is something like: RUN ln -s /lib/systemd/system/httpd.service \ /etc/systemd/system/multi-user.target.wants/ Maybe there's a cleaner way to do this with some `systemctl enable ...` options. I'd love to know about them if anyone else has smart in systemd stuffs :D --- Chris Evich (he/him), RHCA III Senior Quality Assurance Engineer If there's a "hard-way", I'm the first one to implement it. On 9/20/23 15:19, etc@balosh.net wrote:
Hi, question that I don't understand, I'd be grateful for explaining or reference to what I should read to get it.
Why during Podman build command `systemctl enable httpd` is working but `systemctl status httpd` is not working?
Dockerfile not working:
``` FROM registry.access.redhat.com/ubi8/ubi-init RUN yum -y install httpd; yum clean all; RUN systemctl enable httpd; RUN systemctl status httpd; ```
output of `podman build .`:
``` STEP 2/4: RUN yum -y install httpd; yum clean all; STEP 1/4: FROM registry.access.redhat.com/ubi8/ubi-init Build output: --> 02f6efde590f --> Using cache 02f6efde590f9fec989c04a01a661d2650b462aeb8e61ad3c0e00aae1b16b1ef --> Using cache 4f85f566fdee4fd8f5e8058dbf39c5ec9be95a4879d4d9a8c7a77f5b9cadf8a7 STEP 3/4: RUN systemctl enable httpd; STEP 4/4: RUN systemctl status httpd; --> 4f85f566fdee System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down ```
But! If I exec into the container when he is running both of them are working.
Working Dockerfile:
``` FROM registry.access.redhat.com/ubi8/ubi-init RUN yum -y install httpd; yum clean all; RUN systemctl enable httpd; ```
command: `podman build . -t x ; podman run -d --name x x ; podman exec -ti x bash -c "systemctl status httpd"` runs with success
``` STEP 1/3: FROM registry.access.redhat.com/ubi8/ubi-init STEP 2/3: RUN yum -y install httpd; yum clean all; --> Using cache 02f6efde590f9fec989c04a01a661d2650b462aeb8e61ad3c0e00aae1b16b1ef --> 02f6efde590f STEP 3/3: RUN systemctl enable httpd; --> Using cache 4f85f566fdee4fd8f5e8058dbf39c5ec9be95a4879d4d9a8c7a77f5b9cadf8a7 COMMIT x --> 4f85f566fdee Successfully tagged localhost/x:latest 4f85f566fdee4fd8f5e8058dbf39c5ec9be95a4879d4d9a8c7a77f5b9cadf8a7 214ee56866fc0e7d71b6d152749bdcb65d4e5aadb95dafcebb5661ee20770619 [root@214ee56866fc /]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2023-09-19 20:07:22 UTC; 6s ago Docs: man:httpd.service(8) Main PID: 30 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 1638) Memory: 22.3M CGroup: /system.slice/httpd.service ├─30 /usr/sbin/httpd -DFOREGROUND ├─34 /usr/sbin/httpd -DFOREGROUND ├─35 /usr/sbin/httpd -DFOREGROUND ├─36 /usr/sbin/httpd -DFOREGROUND └─37 /usr/sbin/httpd -DFOREGROUND
versions: podman version 4.6.2 on macos ventura 13.5.2 _______________________________________________ Podman mailing list -- podman@lists.podman.io To unsubscribe send an email to podman-leave@lists.podman.io
Hi Chris thanks, but actually the `systemctl enabled` line works perfectly the `systemctl status httpd` is the problem. Here is short screen recording of the podman build: https://youtu.be/yEzixoSMjCk
On 21.09.23 at 15:22 etc@balosh.net wrote:
Hi Chris thanks, but actually the `systemctl enabled` line works perfectly the `systemctl status httpd` is the problem.
My guess would be that the "enable" just does a simple link but needs to running D-Bus session, while the "status" requires that. As there is no running system where should it come from? You could test it "systemctl is-enabled foo.service" works. Kind Regards Johannes -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg http://www.b1-systems.de GF: Ralph Dehner Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
Yes exactly, systemd won't be running, and you'll likely have a difficult time starting it in a build-context. I'm pretty sure it requires a plethora of special mounts (like sys and proc) in addition to "other stuff" (search 'init' and 'systemd' in 'podman run' man page). Lastly just to reiterate: You cannot predict the container runtime options at build time, so shouldn't assume them either. Heck, the image could be a base-image for something else, that provides other needed runtime bits. It's far more reliable to simply create the symlinks yourself during the build. Do your runtime status checks and testing, at runtime. Not build time, it's the wrong context. --- Chris Evich (he/him), RHCA III Senior Quality Assurance Engineer If there's a "hard-way", I'm the first one to implement it. On 9/21/23 10:49, Johannes Kastl wrote:
On 21.09.23 at 15:22 etc@balosh.net wrote:
Hi Chris thanks, but actually the `systemctl enabled` line works perfectly the `systemctl status httpd` is the problem.
My guess would be that the "enable" just does a simple link but needs to running D-Bus session, while the "status" requires that. As there is no running system where should it come from?
You could test it "systemctl is-enabled foo.service" works.
Kind Regards Johannes
_______________________________________________ Podman mailing list -- podman@lists.podman.io To unsubscribe send an email to podman-leave@lists.podman.io
thanks Johannes and Chris. I think I get it, during each "RUN" command, the intermediate image is not running the same as doing podman run at the end in a full "dbus session". So systemctl command that only touch the filesystem would work, systemctl commands that require the session would fail.
participants (3)
-
Chris Evich -
etc@balosh.net -
Johannes Kastl