Modify confg files located on container volume

I am playing around and getting some experience with packaging apps for NS8.
Now i want to make a tcp network port configurable from the cluster-admin.
The UI and firewall stuff i am on top of.

The thing is that it need to be a 1:1 mapping because the service informs clients which port to use. The port number is configured in a config file located on the volume mounted by the container. The files on the volume are owned by the user running the server within the container which means that the action scripts from the imageroot are not permitted to modify those.

I could probably get away with retrieve the file via podman, modify it and put it back (did not test yet).
Or are there a better option to modify content on a container volume?

2 Likes

For small changes you could use podman exec to run commands in the container so it’s possible to modify files, see podman-exec — Podman documentation

podman exec -i containername bash -c "sed -i 's/port: old_port/port: new_port/' /etc/configfile"

Examples:

Another method is to write the config file(s) locally and mount it to the container.

Mount a config directory…

--volume ./config:/etc/myapp:z

…or a config file:

--volume ./config/configfile:/etc/myapp/configfile:z

For example ns8-roundcubemail:

Another example is ns8-ejabberd that uses a config file.

2 Likes

@mrmarkuz, thanks for your detailed answer and the pointers. :slightly_smiling_face:
I was looking at other projects for a answer, but only in the actions scripts, not the systemd service scripts as you proposed, which i find is a nice and clean way to a task like this.

1 Like