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.

Best practices for python container

Featured Replies

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 by theothermatt_b

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.

Guest
Reply to this topic...

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.