BobFish Posted November 1, 2021 Share Posted November 1, 2021 Hi Everyone, super new to unraid and docker but loving it all so far. I've built a discord bot in python which I'd like to run on my unraid server as a docker container. How do I go about doing this in the easiest way? I have been trying to research online on how to do this but not really found any instructions that walked me through it step by step. Thanks Quote Link to comment
knex666 Posted November 1, 2021 Share Posted November 1, 2021 Hey, thats very easy. You create a new container, give it a name and use the source python:3 volume mount your source code folder to /source/ and enter post execution "python3 /source/main.py" if you have some requirements you have to install those with docker exec and commit the container after you made changes. cheers Quote Link to comment
BobFish Posted November 2, 2021 Author Share Posted November 2, 2021 5 hours ago, knex666 said: Hey, thats very easy. You create a new container, give it a name and use the source python:3 volume mount your source code folder to /source/ and enter post execution "python3 /source/main.py" if you have some requirements you have to install those with docker exec and commit the container after you made changes. cheers Thanks for the reply! So I think I'm almost there. I've made a folder here on my unraid server with my dockerfile and my python file And then here is my dockerfile: I then run sudo docker build -t discord -f /mnt/user/Media/discordbot/dockerfile . in my terminal on unraid which if I go docker images gives me this: so I then should just go docker run discord right? but this gives me this error: I think I need to copy the bot.py file somehow to where the docker image is stored or something like that? Very unsure what to do next or if what I have is correct. Thanks! Quote Link to comment
primeval_god Posted November 2, 2021 Share Posted November 2, 2021 (edited) It depends on how you want to go about it. knex666's comment above suggested bind-mounting the your source code into the container (using a -v flag in docker run). That would make it easier to make changes to the source (bot.py) without recreating the container. On the other hand what you have above is most of what you need to build your bot.py directly into the container, which would make it easier to distribute. To finish building your code into the container you need to add a COPY line in you dockerfile to copy bot.py to a location within the filesystem of your image and a WORKDIR line to ensure your container begins running from the proper internal directory. Edited November 2, 2021 by primeval_god Quote Link to comment
BobFish Posted November 2, 2021 Author Share Posted November 2, 2021 Thanks! I've gone ahead and added those lines for wordir and copy but it still seems to be not working and giving me the same error Hope I'm getting closer though! Quote Link to comment
BobFish Posted November 3, 2021 Author Share Posted November 3, 2021 I got it working! instead of running docker build -t discordbot -f PathToFile I navigated to the directory of the file and then run docker build there and that allowed everything to work correctly Quote Link to comment
primeval_god Posted November 3, 2021 Share Posted November 3, 2021 On nitpick, while you can copy everything from the build context into your image like you are above, it might be cleaner to COPY only the bot.py script. Quote Link to comment
lotekjunky Posted December 20, 2021 Share Posted December 20, 2021 (edited) If you're like me and ended up here just trying to get a .py script to run in a container with dependencies, this is how I got it working. Add new cointainer, use the blank template repository: python:latest project page: https://hub.docker.com/_/python icon url: https://d1q6f0aelx0por.cloudfront.net/product-logos/library-python-logo.png post arguments: /bin/bash /app/init.sh map a volume from /mnt/user/appdata/python/this_script -> /app (after you add a single py script, this will be saved as a template and you can just tack on a different directory like "that_script" and keep everything in one place) Put your main.py file in the aforementioned directory, but you must accompany it with an init.sh script. Here's what mine looks like. (Note that both scripts are executable, so chmod +x them): Quote root@blaaaaaarg:/mnt/user/appdata/python/this_script# ls -la total 8 drwxrwxrwx 1 nobody users 28 Dec 17 19:44 ./ drwxrwxrwx 1 root root 12 Dec 19 13:30 ../ -rwxrwxrwx 1 root root 120 Dec 17 19:47 init.sh* -rwxrwxrwx 1 root root 1351 Dec 17 19:36 main.py* root@blaaaaaarg:/mnt/user/appdata/python/crypto# root@blaaaaaarg:/mnt/user/appdata/python/this_script# cat init.sh #!/bin/bash /usr/local/bin/python -m pip install --upgrade pip pip install requests /usr/local/bin/python /app/main.py This method is easily deployable for multiple scripts, and it was so obvious after slowly reading and re-reading @knex666 response over and over again. I don't think this is exactly what he meant, but this works for me. Edited December 20, 2021 by lotekjunky 2 Quote Link to comment
chrisblackton Posted December 15, 2022 Share Posted December 15, 2022 On 12/20/2021 at 6:24 AM, lotekjunky said: Put your main.py file in the aforementioned directory, but you must accompany it with an init.sh script. Here's what mine looks like. (Note that both scripts are executable, so chmod +x them): Quote root@blaaaaaarg:/mnt/user/appdata/python/this_script# ls -la total 8 drwxrwxrwx 1 nobody users 28 Dec 17 19:44 ./ drwxrwxrwx 1 root root 12 Dec 19 13:30 ../ -rwxrwxrwx 1 root root 120 Dec 17 19:47 init.sh* -rwxrwxrwx 1 root root 1351 Dec 17 19:36 main.py* root@blaaaaaarg:/mnt/user/appdata/python/crypto# root@blaaaaaarg:/mnt/user/appdata/python/this_script# cat init.sh #!/bin/bash /usr/local/bin/python -m pip install --upgrade pip pip install requests /usr/local/bin/python /app/main.py Just stumbled upon this. Could you clarify this for me? Are these two separate scripts? Or is it one script that got separated by formatting? Quote Link to comment
Recommended Posts
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.