Jump to content

How to create custom docker image with persistent storage on unraid?


Recommended Posts

Hello, 

 

I am trying to do something very simple, but I lack some knowledge on docker.

 

I have a docker image in a private GitHub repo that updates the image on dockerhub when pushed.

 

Docker file

FROM python:alpine3.17

WORKDIR /apps

COPY . .

CMD [ "python", "app.py" ]

 

Python file

import time

print("Hello unraid docker, just testing first setup")

time.sleep(30)

 

Simple, nothing crazy. Now since I got it working on unraid I wanted to figure out how to add storage to my appdata share like other containers from the community apps do. To start, first I tried to see if I could just make a path from the container to host to at least see if files would show up from the container. I've had to add/change container paths before on community apps to get to different files with no issues.

 

 

unraid_mount.PNG.6b56dc8f143c10404d8adcfa2d72a6dc.PNG

 

The folder in the share comes up and... It's empty... but the apps folder on the container is there with the files added.

 

So I tried other container paths, but nothing, or the container would crash with an exec error. I realize I am missing something. Am I adding the wrong path, or do need to specify a volume in my dockerfile? In other dockerfiles I never see a volume added so I am at a loss.

 

Additionally, how does one give access to the base appdata folder to a docker container so you can monitor files? I've tried using inotify but it didn't have the functionality I was looking for.

Edited by stig
adding more info
Link to comment

Bind mounting gives the docker container access to a folder from the host not the other way around. When you mount the host path /mnt/user/appdata/unraid_testing/ to /apps in the container you are mounting unraid_testing over the apps folder essentially hiding the existing folder in the container. If unraid_testing had files in it they would be accessible inside the container and if something in the container where then to place a file in /apps it would be accessible from the host unraid_testing folder.

Edited by primeval_god
Link to comment
On 4/4/2023 at 10:46 AM, primeval_god said:

Bind mounting gives the docker container access to a folder from the host not the other way around. When you mount the host path /mnt/user/appdata/unraid_testing/ to /apps in the container you are mounting unraid_testing over the apps folder essentially hiding the existing folder in the container. If unraid_testing had files in it they would be accessible inside the container and if something in the container where then to place a file in /apps it would be accessible from the host unraid_testing folder.

Okay I think I understand this. I ran a couple more tests and see what you are saying, but how would I modify my dockerfile to have the files already in it when I set the bind mount? Do I need to add a volume and then copy the files over or do something in the CMD script?

Link to comment
11 hours ago, stig said:

Okay I think I understand this. I ran a couple more tests and see what you are saying, but how would I modify my dockerfile to have the files already in it when I set the bind mount? Do I need to add a volume and then copy the files over or do something in the CMD script?

If you want to put files into the bind mount directory it has to be done at runtime. You would need to put the files somewhere else in the image, then have a script that runs when the container starts to copy them to the bind mount directory if they are not already there.

Link to comment
On 4/6/2023 at 10:20 AM, primeval_god said:

If you want to put files into the bind mount directory it has to be done at runtime. You would need to put the files somewhere else in the image, then have a script that runs when the container starts to copy them to the bind mount directory if they are not already there.

Okay I will try this. Is this usually how other community docker apps do this for accessing files?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...