#🔒 Docker Error when Binding Volume

53 messages · Page 1 of 1 (latest)

tropic dagger
#

python: can't open file '/app/main_bot.py': [Errno 2] No such file or directory

Not sure why binding a path to the host would cause this error.

feral glacierBOT
#

@tropic dagger

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tropic dagger
#

Im not exactly sure why?

#

this is my dockerfile

# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory
WORKDIR /app

# Copy the requirements file
COPY requirements.txt ./

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code
COPY . /app

# Command to run the application
CMD ["python", "main_bot.py"]
meager ember
#

If you bind a directory from the host into the container, it will hide whatever's at the in-container mount point. You're binding it to /app, hiding what you copied into /app in the dockerfile.

tropic dagger
#

Cuz im still learning docker, it's been a confusing process despite all the videos

meager ember
#

Bind it to somewhere else? Or copy main_bot.py etc to somewhere else

tropic dagger
#

I just want the program files to be mounted to a specific location so if I every update or delete the bot, all the settings stay there

meager ember
#

Ah right.

#

Is there a main_bot.py in the tree you're mounting into the container?

tropic dagger
#

This is basically the project

meager ember
#

That looks like it isn't the directory you mounted in?

#

It's got spaces in the name in the screenshot above.

tropic dagger
#

With how i've learned docker, for example when I build it. All this goes to "/app"

#

I use visual studio code to push this into docker hub

meager ember
#

/app is a typical place to install whatever you're plonking into the container.

tropic dagger
#

I pull it from docker hub onto my home server,

#

and so I tried to redirect /app to /mnt/cloud1/Example/app

meager ember
#

So your VSCode above is not on the home server. Where's /mnt/cloud1 come from? Is it related to whatever VSCode is looking at?

tropic dagger
#

/mnt/cloud1 is a mounted drive on my home server

#

which is running ubuntu server

#

basically anything inside that directory goes to my 2TB Hard Drive

#

But, that's a whole thing

#

Basically my issue is, I don't understand why changing the volume causes this issue

#

because technically speaking, inside the docker container, all it sees is still /app, it doesn't know it's inside /mnt/cloud1/Example/app

#

unless that isn't how that works

meager ember
#

Right. So I'm assuming that after you bind it in, /app doesn't contain what it should.

#

So where's the container running? That GUI above with the mount options. Loca to your dev box with VSCode, or remote on your home server?

tropic dagger
#

Sort of like a remote yes

#

im accessing portainer from a web browser

#

Portainer is basically a web UI for docker

#

I mean, I guess for now I just don't mount it to a specific path like im trying.

meager ember
#

Ok. Back to the container. Running on your home server? Running in the cloud at portainer somehow?

#

So this:
is the portainer web UI?

tropic dagger
#

No, it's a local system. Accessing via local IP + port

#

Correct

meager ember
#

If it's local, can you look in that directory?

tropic dagger
#

yes, nothing

#

the directory is empty

meager ember
#

Well then you've mounted am empty directory onto /app, and thus there's no main_bot.py. Do I misunderstand?

tropic dagger
#

this is what the docker container should create when it pulls from docker hub

meager ember
#

That's inside the container?

tropic dagger
#

yes, this is inside the container

meager ember
#

Yes. That's what's there before you bind in this other directory.

tropic dagger
#

but I wanted to push this to be in /mnt/cloud1 on my main host

meager ember
#

So /mnt/cloud1 is off yoru 2TB drive on the home server?

tropic dagger
#

yes

meager ember
#

Can you rsync from your (local?) VSCode directory onto that? To make the copy at home (in the currently empty cloud1/DATA/gumroad-product-announcer-discordbot directory) have your dev files?

feral glacierBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.