egima egima - 2 months ago 20
Linux Question

windows "C:/Users/<username>/" directories not visible during `docker build` command

From what I know,

docker-machine
automatically mounts the
C:/Users/<username>
directory in windows. I am able to access it from the quick start terminal as
/c/Users/<username>
and perform all sorts of operations on it.


However when I
RUN
a command from inside
Dockerfile
, docker engine simply doesn't recognize this mounted path.

For instance I have
activator
zip located at:

/c/Users/someuser/somefolder/typesafe-activator-1.3.10.zip


Previously, I was using
wget
in
Dockerfile
:

RUN wget https://downloads.typesafe.com/typesafe-activator/1.3.10/typesafe-ctivator-1.3.10.zip && unzip typesafe-activator-1.3.10.zip


Now since I already have this zip in the file system, I want to:

RUN cp /c/Users/someuser/somefolder/typesafe-activator-1.3.10.zip . && unzip typesafe-activator-1.3.10.zip


But I get:


cp:cannot stat '/c/Users/someuser/somefolder/typesafe-activator-1.3.10.zip': No such file or directory


Any one know how I can get a file from the shared folders on the host machine into the docker build process?

UPDATE
Here is my complete
Dockerfile
:

FROM openjdk:8
ENV PROJECT_WORKPLACE /usr/src
RUN mkdir -p $PROJECT_WORKPLACE/activator $PROJECT_WORKPLACE/build $PROJECT_WORKPLACE/app

WORKDIR $PROJECT_WORKPLACE/activator

COPY . typesafe-activator-1.3.10.zip
RUN unzip typesafe-activator-1.3.10

ENV PATH $PROJECT_WORKPLACE/activator/typesafe-activator-1.3.10/activator-dist-1.3.10/bin:$PATH

COPY . $PROJECT_WORKPLACE/build

WORKDIR $PROJECT_WORKPLACE/build

RUN activator clean stage

RUN cp -R $PROJECT_WORKPLACE/build/target/universal/stage $PROJECT_WORKPLACE/app

EXPOSE 9000

CMD $PROJECT_WORKPLACE/app/stage/bin/docker-play -Dhttp.port=9000 -Dlogger.file=$PROJECT_WORKPLACE/build/logger.xml

Answer

The RUN sees the Dockerfile context:

The context is the current folder (where the Dockerfile is) and its subfolder.

The docker build command builds an image from a Dockerfile and a context.
The build’s context is the files at a specified location PATH or URL.
The PATH is a directory on your local filesystem.
The URL is a the location of a Git repository.

A context is processed recursively. So, a PATH includes any subdirectories and the URL includes the repository and its submodules.

Therefore, You don't need to specify the all path.

RUN cp typesafe-activator-1.3.10.zip . && unzip typesafe-activator-1.3.10.zip

Note: you should use COPY or ADD instead of RUN cp

COPY typesafe-activator-1.3.10.zip .
RUN unzip typesafe-activator-1.3.10.zip

In any case, any resource you need should be in the same folder or subfolder of your Dockerfile.

The OP egima made it work with:

ADD typesafe-activator-1.3.10.zip .