0

Error when trying to copy folder with absolute path COPY /src/www/ /usr/share/nginx/html/ in Dockerfile

Step 3/4 : COPY /src/www/ /usr/share/nginx/html/ COPY failed: stat /var/lib/docker/tmp/docker-builder685852786/src/www: no such file or directory

Error when trying to copy folder with relative path COPY ../../../src/www/ /usr/share/nginx/html/ in Dockerfile

Step 3/4 : COPY ../../../src/www/ /usr/share/nginx/html/ COPY failed: Forbidden path outside the build context: ../../../src/www/ () ERROR: Job failed: exit code 1

My folders are like this:

------docker-compose.yml
|_____.gitlab-ci.yml  
L_______infrastructure
|   L_____docker
|      L______nginx
|         L____Dockerfile
L______src
   L____www

enter image description here

I'm running Dockerfile directly from .gitlab-ci.yml with docker build --pull -t "$CI_REGISTRY_IMAGE" ./infrastructure/docker/nginx/.

Dockerfile is:

FROM nginx:stable
MAINTAINER Salle MPWAR Maintainers
COPY /src/www/ /usr/share/nginx/html/
// or COPY ../../../src/www/ /usr/share/nginx/html/ I tried both

I'm missing something with the routes can't make it work with absolute or relative paths.

So as it's explained in this question, I changed the .gitlab-ci.yml command with docker build --pull -t "$CI_REGISTRY_IMAGE" -f ./infrastructure/docker/nginx/Dockerfile .

And the Dockerfile COPY command with COPY ./src/www/ /usr/share/nginx/html/

But it didn't solve my question, as now I have the error:

Step 3/3 : COPY ../../../src/www /usr/share/nginx/html COPY failed: Forbidden path outside the build context: ../../../src/www () ERROR: Job failed: exit code 1

Alex
  • 1,230
  • 2
  • 24
  • 46
  • I think a good practice will be to keep Dockerfile at the root of your project directory. – Shubham Dec 14 '19 at 11:55
  • I think so, but I've been forced to place dockerfile at this folder – Alex Dec 14 '19 at 11:56
  • From the top level, run `docker build -f ./infrastructure/docker/nginx/Dockerfile .`. That makes the context directory be the root of your source tree (and `COPY ./src` will be relative to the right place). – David Maze Dec 14 '19 at 11:59
  • I just tried with your response, but I hget the error: `Step 3/4 : COPY ./src/www/ /usr/share/nginx/html/ COPY failed: stat /var/lib/docker/tmp/docker-builder674070819/src/www: no such file or directory` – Alex Dec 14 '19 at 12:06

0 Answers0