Share Folders (VOLUME) with Docker Container

I want to use a Docker container with a permanent data storage. I use the example Dockerfile from Xojo Blog https://blog.xojo.com/2025/03/19/a-complete-dockerfile-for-web-apps/. However, I am not able to save an SQL database from the Xojo Web App in the directory /home/HelloDocker/data.

I thought that I could access it from the Xojo app like this:
Var dataFolder As FolderItem = SpecialFolder.UserHome.Child(“HelloDocker”).Child(“data”)

But nothing happens in the folder. If I even write this in the opening event of the app, the web page remains dark. But it works as a local app. Does anyone have a tip for me as to what could be wrong?

I have tried to integrate the VOLUME on the Synology:

Well, you are mounting the Synology-Folder into the Docker Container at /home/HelloDocker/data.

And you try to get it (running from a process - the WebApp - in the Docker Container) with SpecialFolder.UserHome.
This would only work if “UserHome” is /home/HelloDocker - which most likely is NOT the case :wink:

Either you figure out what “UserHome” really point to in your Docker Container (and mount the Synology-Folder to the correct location)
…or you mount the Folder into e.g. /data, and in your WebApp you get it from /data.

That’s just to get started :wink:

Of course it’s not quite nice to hardcode a path into a (Web)App.

For WebApps that run in various environments you should allow to configure these settings via Environment Variables (and/or Launch Arguments).

See for example: cubesql/webadmin: modCubeSQLAdmin.xojo_code

Then you can start the Docker Container with the Environment Variable set to the location where you have mounted the data folder.
If Environment Variable is not set, you still can fall back to “UserHome”, so that it works on your local machine, too.

Thank you @Jürg_Otter for the quick reply. It is more complicated than I first assumed. I will try to work though your advice.

Either you figure out what “UserHome” really point to in your Docker Container (and mount the Synology-Folder to the correct location)

But one more question about my understanding. /home/ in the docker container is not the same as UserHome in the web app?

And if I have specified /home/HelloDocker/data as VOLUME in the Dockerfile. Then I need to specify that exact path as the mapped folder on the Synology, correct?

ENV WEBAPP_NAME=HelloDocker
WORKDIR /${WEBAPP_NAME}

# Define the volume for the container to store data.
# The contents of "/home/${WEBAPP_NAME}/data" will persist outside the container.
VOLUME /home/${WEBAPP_NAME}/data
1 Like

A docker container is basically it’s own virtual machine. the paths and data inside a docker container, are it’s own, just like a normal computer. the dockerfile defines a volume that will be persistent after each docker container restart. the volume though, it’s managed by docker itself. what you are looking for is this command to start the docker container:

docker run -d --name hellodocker-container --restart always -p 7000:80 -v /path/to/your/local-host-machine/data-folder:/home/HelloDocker/data hellodocker-image

so, the Xojo webapp will store and use files with SpecialFolder.ApplicationData.Child("data")

Hope this helps!

2 Likes

Thanks for the tip. I tried it and it didn’t work at first either. Then I realized that it must have something to do with the read/write permissions. I changed the folder permission to Everyone Read & Write and then the web app saved the SQL database there too. That was exactly what I wanted.
The only thing I find strange is that I have multiple Docker containers on my Synology with mapped folders and there were never any issues with the write permissions.
After that, it made no difference whether I used ApplicationData or UserHome.