4

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?

Dean MacGregor
  • 11,847
  • 9
  • 34
  • 72

2 Answers2

2

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 the devcontainer.json file to .. and change the Dockerfile copy command to COPY requirements.txt /tmp/pip-tmp/. Other COPY 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.

Com
  • 106
  • 6
1

Since it works if you put requirements.txt inside .devcontainer/, the problem is the path you are using in the COPY instruction. By doing COPY requirements.txt ... you instruct the Dockerfile to search for requirements.txt in its working directory which is .devcontainer/.

By using COPY ../requirements.txt ... you'll instruct it to search for requirements.txt in .devcontainer/'s parent folder, which is app-dash/ and where requirements.txt is actually located.

So just replace the COPY instruction with:

    COPY ../requirements.txt /tmp/pip-tmp/
Anton
  • 291
  • 1
  • 5
  • 1
    nope, same error. – Dean MacGregor Nov 02 '22 at 19:32
  • Have you checked the permissions of the file? Can you post the logged error so we can see what exactly is happening? – Anton Nov 02 '22 at 20:51
  • Yeah, this doesnt work. we need to change the build context to solve this. i know how to do this when building docker on command line or when using a docker-compose file. i dont know how to do it with devcontainer.json in vsc – mike01010 Jun 02 '23 at 22:15