My directory structure is this:
app-dash
.devcontainer
devcontainer.json
Dockerfile
app.py
requirements.txt
etc.files
I want to have these lines in my Dockerfile
COPY requirements.txt /tmp/pip-tmp/
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt
&& rm -rf /tmp/pip-tmp
using this line doesn’t work either (with the same error)…
COPY ../requirements.txt /tmp/pip-tmp/
I’ve also
but in the build process it errors out because it can’t find requirements.txt. If I copy requirements.txt to the .devcontainer directory it’ll work. Of course, I don’t want to do that because then if I update one requirements and forget the other it’ll be an issue later. I don’t want to only house the requirements.txt in .devcontainer because I want to host this in azure functions which will expect the requirements.txt to be in the root folder. I also don’t want to have to run the build from the command line.
How can I set it up so that when I click to Open Folder in Container
from vsc that it’ll just do it?
2
Answers
Since it works if you put
requirements.txt
inside.devcontainer/
, the problem is the path you are using in the COPY instruction. By doingCOPY requirements.txt ...
you instruct the Dockerfile to search forrequirements.txt
in its working directory which is.devcontainer/
.By using
COPY ../requirements.txt ...
you’ll instruct it to search forrequirements.txt
in.devcontainer/
‘s parent folder, which isapp-dash/
and whererequirements.txt
is actually located.So just replace the COPY instruction with:
The
COPY ../requirements.txt
seems to resolve to/requirements.txt
which creates the issue.A quick fix is to change the
"build": {"context": "."}}
property in thedevcontainer.json
file to..
and change the Dockerfile copy command toCOPY requirements.txt /tmp/pip-tmp/
. OtherCOPY
commands will need to be updated if they’re copying anything from the .devcontainer folder, e.g.COPY .devcontainer/foo foo
as the context becomes the parent folder containing the.devcontainer
folder.