I have my own directory structure:
+projects
+project_1
+project_2
+node
+container_1
-Dockerfile
in my Dockerfile I copy project_1 to /var/www/project_1 directory but unfortunately it is not copied:
#Dockerfile
FROM node:17
WORKDIR /var/www/project_1
COPY ../../projects/project_1 /var/www/project_1
RUN npm install
CMD ["npm","run","start:dev"]
Error:
=> ERROR [3/4] COPY ../../projects/project_1 /var/www/project_1 0.0s
------
> [3/4] COPY ../../projects/project_1 /var/www/project_1:
------
failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/projects/project_1" not found: not found
You can't do it because docker creators want it that way and as the creators, they have good reasons: simplicity and or security.
Docker at build time, will only work with files or folders which are at the same folder of the Dockerfile.
There are some workarounds like launch the docker build... from one folder and specify the location of Dockerfile which is in another folder.
Check these answer to get more details:
At build time, you should not depend of external folders or files. You must only need of a git repository with the source code of one application. This is common, widely used and devops compatible.
Any other dependency required at build time, should be by good engineering:
FROM acme-base-nodejs or in docker multi-stageFiles that you want to COPY should be located within the Dockerfile directory and not outside (eg. parent).
+projects
+project_1
+project_2
+node
+container_1
+Dockerfile # <-- move your Dockerfile to your project root.
Update your files location in the Dockerfile:
...
COPY ./projects/project_1 /var/www/project_1
...
Build will success when run at the project root:
docker build -t <my tag> .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With