skip to Main Content

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


  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/
    
    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search