1

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 wgetin 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
egimaben
  • 653
  • 7
  • 22

1 Answers1

1

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 .
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • that was the perfect tweak I needed for including resources though I had to add a period after `COPY`. However, new issues are up. I have added the complete `Dockerfile`. At the `unzip` step, I get `unzip: cannot find or open typesafe-activator-1.3.10, typesafe-activator-1.3.10.zip or typesafe-activator-1.3.10.ZIP` – egimaben Sep 20 '16 at 08:59
  • @egima try adding, after the `COPY`, a `RUN pwd`, and `RUN ls` to get a sense of where you did the copy. – VonC Sep 20 '16 at 09:01
  • Tried, for some reason, replacing `COPY` with `ADD` and swapping the positions of period (src) with filename(destination) worked. thanks – egimaben Sep 20 '16 at 09:32
  • @egima Great: what exact command did you use then? `ADD typesafe-activator-1.3.10.zip .` ? – VonC Sep 20 '16 at 11:33
  • sure, that's the exact one I used – egimaben Sep 20 '16 at 11:37
  • @egima Great. I have included it to the answer for more visibility, and for others to benefit from. – VonC Sep 20 '16 at 11:44
  • can you checkout [this one](http://stackoverflow.com/questions/39636072/sbt-failed-download-in-running-play-docker-container) too – egimaben Sep 22 '16 at 10:06