Dockerfile script to move directores and create symlinks

I have an application (.rpm) that I am installing which has two directories that contain the configuration information and logs (hence must persist). I have created a volume in the Dockerfile and then created a simple script that removes old symlinks, moves the directories to my volume and then recreates the symlinks to the new location.

If I don’t run the script via Dockerfile, but manually run the script inside the image everything works. If however, the script is included in the Dockerfile; the directories are not relocated to my volume.

My assumption is that moving the directories to the volume isn’t supported.

I would be interested if anyone has come across something like this and overcome it.

Hi,

When and how the volumes are declared in your Dockerfile?

There’s a little gotcha that you must pay attention to:

Note: If any build steps change the data within the volume after it has been declared, those changes will be discarded.

HTH,
Alexandre

That’s interesting. Then my interpretation is that instead of running the script at all, I should just be able to follow the rpm install with those volumes I wish to persist; like /var/myapp/logs and /etc/myapp/conf?

So in my Dockerfile, it’d be like…

RUN rpm -i myapp.rpm
VOLUME /var/myapp/logs
VOLUME /etc/myapp/conf

I tested it with touching a file in the declared volume, and that file did not persist. Have I missunderstood?

Apparently what I thought could happen; cannot. Also, if i manually start the image with -v /myapp/logs:/var/myapp/logs the permissions cannot be adjusted on the volume so the application cannot write to it and it just crashes. There does not appear anyway to solve the problems easily… bummer.

It was fun to play around with it anyway.

Un-docked. :frowning: