4

I am using COPY command in my docker file on top of ubuntu 16.04. I am getting error as no such file or directory eventhough the directory is present. In the below docker file I want to copy the directory "auth" present inside workspace directory to the docker image (at path /home/ubuntu) and then build the image.

FROM ubuntu:16.04
RUN apt-get update
COPY /home/ubuntu/authentication/workspace   /home/ubuntu
WORKDIR /home/ubuntu/auth
jason_1093
  • 667
  • 4
  • 9
  • 16

1 Answers1

1

a Dockerfile COPY command can only refer to files under the context - the current location of the Dockerfile, aka . so you have a few options now:

  1. if it is possible to copy the /home/ubuntu/authentication/workspace/ directory content to somewhere inside your project before the build (so now it will be included in your Dockerfile context and you can access it via COPY ./path/to/content /home/ubuntu) it can be great. but sometimes you dont want it.

  2. instead of copying the directory, bind it to your container via a volume:

when you run the container, add a -v option:

docker run [....] -v /home/ubuntu/authentication/workspace:/home/ubuntu [...]

mind that a volume is designed so any change you made inside the container dir(/home/ubuntu) will affect the bound directory on your host side (/home/ubuntu/authentication/workspace) and vice versa.

  1. i found a something over here: this guy is forcing the Dockerfile to accept his context- he is sitting inside the /home/ubuntu/authentication/workspace/ directory, and running there

    docker build . -f /path/to/Dockerfile

so now inside his Dockerfile he can refer to /home/ubuntu/authentication/workspace as his context (.)

Efrat Levitan
  • 5,181
  • 2
  • 19
  • 40
  • `COPY /home/ubuntu/authentication/workspace/* /home/ubuntu/` `COPY failed: no source files were specified` – jason_1093 Mar 24 '19 at 19:17
  • sorry, my bad. fixed now. but if you get a `COPY failed: no source files were specified` error, it might be because in your own `/home/ubuntu/authentication/workspace` directory is empty. this worth a check. – Efrat Levitan Mar 24 '19 at 20:02
  • I tried the same command earlier that you wrote above but this also doesn't seem to work. I can clearly see the directory is present inside the workspace by executing ls command. – jason_1093 Mar 24 '19 at 21:12
  • you were right. i made some research, hope it will be helpfull now. – Efrat Levitan Mar 25 '19 at 23:24