Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dockerizing a python 3 script and saving data to share.

Featured Replies

Hello everyone.

I have created a python script that runs indefinitely. It downloads security camera PNGs from a url and saves it to a folder called images.

I wanted to run this on my Unraid docker but seem to have trouble.

 

I created the dockerfile with the following content.

 

FROM python:3.8
RUN pip install --upgrade pip
COPY main.py /
COPY requirements.txt .
RUN pip install -r requirements.txt
CMD [ "python", "./main.py"]

and I have the following sanitized python 3 script

import itertools
import pendulum
import requests


source = {"source_1": "Source=1_URL",
          "source_2": "Source=2_URL"}


for k, v in itertools.cycle(source.items()):
    print(k, v)
    image_url = v

    img_data = requests.get(image_url)
    img_name = f"images/{k}_{pendulum.now().format('YYYY_MM_DD_HH.mm.ss')}.png"
    with open(img_name, 'wb') as handler:
        handler.write(img_data.content)

When I create the docker image, I added the `/images` path where the container path is `/images' and the host path is a share i made under '/mnt/user/BH/'

 

if I run it and look in the share, there is nothing at all. But if I console into the running image, I see the images.

Can anyone help me understand what I need to do to place the images in the shared folder?

 

I have a feeling I didn't setup the Dockerfile correctly or maybe I need to change the path to my python script.

Thanks for your help.

Are you sure the full path inside the container is really /images (i.e. it as at the top level of the container file system) ?   The code you posted has no leading / on the name which means it is a path relative to the current folder.   When you console into the container you might want to check with the pwd command what is the current folder.

  • Author

Thanks for the response. When I console in and check pwd I get a simple / which tells me this is the root. and when I list the directory I see the images directory. So I'm not certain how to point to it.

Could you point me to a guide or reference to properly setup my container for this script. I don't expect anyone to do the work for me but I could certainly use a nudge.

Thanks.

Edit: even with / in front of my images directly (in python script) it does not resolve the issue.
 

Edited by HH0718
Supplemental information.

  • Community Expert

You might try placing a file (with a recognizable name) in /mnt/user/BH/ on unRAID and then exec into you container and confirm it is where you expect it to be (search for it if neccissary). That way you can confirm that your mounts are setup the correct way.

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.