October 10, 20241 yr Hi all, I can write mediocre python, but I'm still very new to things like virtual environments and things like that. I have a python discord bot running in a python docker container. To be clear: it's working. But I've been reading about venv's due to getting this message whenever I start the container: Quote WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning. I see that I can suppress the message but... should i? Should i be running python in a venv instead? Is that... better somehow? I don't intend on distributing this container, running multiple bots, or anything fancy, if that helps. It also appears to be the case that every time i start the container, it needs to re-download all the extra libraries (discord.py, and about a dozen others) every single time. That seems less than efficient. Would a venv resolve that as well? My init.sh looks like this: python -m pip install --upgrade pip python -m pip install -r app/requirements.txt python /app/mombot.py If I comment out those first two lines, it won't start because its missing discord and the rest. So it seems like they have to install every time. Edited October 10, 20241 yr by theothermatt_b
October 10, 20241 yr I am not a python expert but I dont think that warning is particularly relevant in a single application docker container. There is not much system in the container to worry about interfering with. As for the second part I dont think a venv would help, unless its base directory was stored outside the container. What you need is a way to run the install commands only on the first startup of the container. Some containers have a framework for some sort of first run script. You could achieve the same by checking for and creating a lock files somewhere in the containers internal filesystem.
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.