I try to build my docker file but it has failed.
I have folder structure in vscode like that:-
In my docker file have only few command:-
COPY requirements.txt /tmp/pip-tmp/
RUN pip install -r /tmp/pip-tmp/requirements.txt \
&& rm -rf /tmp/pip-tmp
I got an error messege:-
PS C:\LearbayDatascience> docker build -t proj:myapp /.devcontainer
unable to prepare context: path "/.devcontainer" not found
PS C:\LearbayDatascience> docker build -t proj:myapp C:/LearbayDatascience/.devcontainer
[ ] Building 0.6s (7/8)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye 0.5s
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> [1/4] FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye@sha256:21a12816fcadaa16dabb4ba0e8c358361d02ea062b1b89db8786eb67173489d0 0.0s
=> CACHED [2/4] RUN if [ "none" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install none 2>&1"; fi 0.0s
=> ERROR [3/4] COPY requirements.txt /tmp/pip-tmp/requirements.txt 0.0s
------
> [3/4] COPY requirements.txt /tmp/pip-tmp/requirements.txt:
------
failed to compute cache key: "/requirements.txt" not found: not found
why requirments.txt
is not found when I run the command from same folder structure.
If I rebuild with vscode .devcontainer
is loaded successfully.
Please help in this regards.
CodePudding user response:
Try putting the dockerfile
in the same dir as the requirements.txt
Then in your Dockerfile
COPY ./requirements.txt /tmp/pip-tmp/requirements.txt
RUN pip install -r /tmp/pip-tmp/requirements.txt \
&& rm -rf /tmp/pip-tmp
After this navigate to the folder where Dockerfile is located and pass as the build command
docker build -t proj:myapp .