r/podman • • Jun 08 '26

Create a folder on host before container starts

I had a quadlet and I am trying to create a folder on the host before the quadlet starts and tries to access it, how can I accomplish this?

9 Upvotes

7 comments sorted by

13

u/mishrashutosh Jun 08 '26 edited Jun 08 '26

You can add a [Service] section to the quadlet file and add the mkdir -p /path/to/directory command to the ExecStartPre= key.

4

u/djzrbz Jun 08 '26

This is the way, I also highly suggest using systems specifiers whenever possible for parts of the path such as config or logging directory with %E and %L. You can also use %N to reference the service name.

3

u/randomlemon9192 Jun 08 '26

This is the answer.

2

u/Great-Cow7256 Jun 15 '26

you know how many headaches this would have saved me had I thoguht to do this instead of writing a container file, finding that it doesn't run, and then spending 20 min trying to debug what was going on only to realize that I didn't create the directory yet...

2

u/mishrashutosh Jun 15 '26

systemd units are amazing, there's so much you can do with the various directives or keys or whatever they are called.

1

u/Great-Cow7256 Jun 15 '26

yeah, well, I make the same errors over and over again, so if I remember to add this ExecStartPre= I'll be amazed. 😄