1

I have successfully built my docker image for a play-java. But while trying to spawn a container for it with docker run -p 0.0.0.0:9000:9000 egima/play activator run sbt fails to download one particular dependency. The log looks like this:

==== Maven2 Local: tried
  file:/root/.m2/repository/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0.jar
==== Apache Repository: tried  https://repository.apache.org/content/repositories/releases/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0.jar[0m
    ::::::::::::::::::::::::::::::::::::::::::::::
    ::              FAILED DOWNLOADS            ::
    :: ^ see resolution messages for details  ^ ::
    ::::::::::::::::::::::::::::::::::::::::::::::
    :: org.sonatype.sisu#sisu-guice;3.1.0!sisu-guice.jar
    ::::::::::::::::::::::::::::::::::::::::::::::

Notice the the tried repositories. I have followed all the different variants for including the local maven repos on my machine, I confirm from the logs that sbt checks according to what I have specified in the local maven repos but no luck.

My resolvers in both build.sbt and /project/plugins.sbt:

resolvers ++=Seq(
    Resolver.sonatypeRepo("public"),
    Resolver.mavenLocal,
    "Apache Repository" at "https://repository.apache.org/content/repositories/releases/"
    )

I also checked my local maven repo to ensure the missing dependency exists. What is missing?

Community
  • 1
  • 1
egimaben
  • 653
  • 7
  • 22
  • /root/.m2? Why using the root account? – VonC Sep 22 '16 at 11:57
  • @VonC, that path is automatically converted by `sbt` from `Resolver.mavenLocal`. I also tried the paths that worked for others in the linked question, still no luck. – egimaben Sep 22 '16 at 12:01
  • Sure: it resolves to $HOME/.m2. Is that folder empty? Shouldn't it contain some elements? Do you have a local .m2 folder that you should share (-v)? – VonC Sep 22 '16 at 12:04
  • In windows, I have `C:\Users\me\.m2\repository`, not sure if by `/root/.m2` sbt means `C:\Users\me\.m2`. But the host path I have given is very valid and stores all my maven artifacts. – egimaben Sep 22 '16 at 12:12
  • 1
    Try, in your dockerfile a `RUN ln -s /C/Users/me/.m2 /root/.m2`: rebuild the image and relaunch the container. – VonC Sep 22 '16 at 12:14
  • @VonC. This command exposed other findings which I have documented in a complete answer, let me know what you think. – egimaben Sep 22 '16 at 13:11

1 Answers1

1

VonC suggested in the comments section to add the following step in Dockerfile:

RUN ln -s /C/Users/me/.m2 /root/.m2

I believe this command should establish a soft link between $MAVEN_HOME on my host machine and the resolution path Resolver.mavenLocal which resolves to /root/.m2.

This should be the solution. However, after trying it, I realized that the shared path /c/Users/me(invisible with capital C, don't know why) is visible inside the VM but invisible inside a container. So including that line inside Dockerfile would give me:

ln:cannot access /c/Users/me/.m2: No such file or directory

Additionally, even performing RUN ls /root would give me a similar error meaning the destination path too does not yet exist at this time.

My own deduction is that the solution lies in mounting the host path onto the destination path by any method available which I think is a well discussed topic on this forum. For my particular situation performing a mount during docker run with the -v flag solved the problem.

This is the exact command I used:

docker run -v /c/Users/me/.m2:/root/.m2 -p 0.0.0.0:9000:9000 egima/play activator run

I have written a complete blog post about his for those that need more information.

Community
  • 1
  • 1
egimaben
  • 653
  • 7
  • 22