sbt failed download in running play docker contain

2019-05-30 13:14发布

问题:

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?

回答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.