Converting a Python scrip to a docker image


Recommended Posts

Ok so i use the following script at

 

https://github.com/airship-david/Trailer-Downloader

 

I would love to dockerise this, that runs at set intervals (cron maybe), has access to my movies folder in unraid and auto updates daily with the latest git hub release as and when. The issue i have is i have 0 clue on docker, and the more i read, the more confused i get. Can anyone convert and dockerise this for me or at least give me some pointers on how best to achieve it.

 

The download_all script should run through my movie library at set time periods, picking up any new trailers configured in the settings.ini file (that would be cool to be editable via the unraid user interface).

 

Much appreciated

Edited by danz0l
added more detail
Link to comment

The Dockerfile would be something like this:

FROM alpine:edge
COPY settings.ini download_all.py requirements.txt /
RUN apk update && apk upgrade && apk add python3 py3-pip && python3 -m pip install -r requirements.txt && echo '* 8 * * * python3 download_all.py --directory /movies' | crontab -
CMD crond -f

You could build the docker image with this:

docker build -t danz0l/trailerdl .

And start it like (put the real path to your movies there instead of /mnt/user/Media/movies):

docker run -h trailerdl --mount type=bind,source=/mnt/user/Media/movies,target=/movies  --name trailerdl -d danz0l/trailerdl

Get familiar with these basic docker commands:

docker help
docker $cmd --help
docker images
docker ps
docker ps -a
docker stop $id
docker rm $id
docker rmi $imageId
docker logs $id

You can get a shell and test things by hand with:

docker exec --it $containerID sh

If you want to be able to install it from the private apps section of Community Apps it will take more work but it is doable.  Check out:

 

As for keeping it up to date every day, that is left as an exercise for the reader.

But if it was me I would do this:  Instead of using the COPY command for the python script, I would use another --mount argument to share a dir where the script lives on unraid to the container, and update the script with wget every day on unraid (not in the container).  Then it will stay updated and you won't have to rebuild the image every time.

Edited by uek2wooF
typo
Link to comment

oh all of that sounds probably far more complex than it likely is. Im not adverse to linux, but ive never really understood the docker concept beyond enabling and using the CA plugin to bring them down. But i'll certainly have a play as i think this project has good traction and is deployable and beneficial for lots of media center users. 

 

I'll look to the user Script plugin too.

 

I'm currently running the script under a local ubuntu vm but it does seem overkill for something so small.

 

What would be a good is using unraids interface to add the settings.ini per item for the user. 

 

One question that always confuses me, is how do i give it access to local files outside of the docker. Obviously all my media files are stored through unraid on various disks within the array.

 

And thanks so much for all the effort put in to trying to explain it to me. Im a quick learning but docker just seems alien to me currently.

Link to comment
On 4/6/2020 at 5:24 AM, danz0l said:

One question that always confuses me, is how do i give it access to local files outside of the docker. Obviously all my media files are stored through unraid on various disks within the array.

On 4/6/2020 at 1:09 AM, uek2wooF said:

--mount type=bind,source=/mnt/user/Media/movies,target=/movies

 

This portion in the run command posted above maps the host directory /mnt/user/Media/Movies to the container directory /movies. Where /mnt/user is the path to the user shares file system on unRAID and /Media/Movies would be a Movies folder within a share named Media. Anything running within the container will see the contents of the /mnt/user/Media/Movies folder under the folder path /movies. This is newer docker syntax that is functionally equivalent to using -v /mnt/user/Media/Movies:/movies 

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.