Resources defined through mappings not copied into Docker
See original GitHub issueI am trying to package a scala server app into a Docker
Expected behaviour
I am suppose to get my application
and a directory with some resources in the docker image.
Actual behaviour
Only application
in /opt/docker/bin
and dependency jars in opt/docker/lib
are copied.
The resources defined through the mappings
mechanism are not copied.
Information
I use:
- sbt-native-packager 1.7.3
- sbt 1.3.10
- OS: Ubuntu 20.04
- packaging java application into a docker
- My piece of code:
lazy val application = project.in(file("application")) settings (defaultSettings) dependsOn (server) enablePlugins (JavaServerAppPackaging) settings(
mappings in Universal ++= {
val prefix = "target/webapp"
Seq(
(dependencyFile in client in Compile).value -> s"$prefix/js/connect-deps.js",
(fullOptJS in client in Compile).value.data -> s"$prefix/js/connect.js"
) ++ doMapping((resourceDirectory in client in Compile).value, "target") ++ doMapping((cssFile in client in Compile).value, s"$prefix/css/")
},
dockerEntrypoint in Universal := Seq("/opt/docker/bin/application"),
packageName in Universal := "openmole-connect",
organization in Universal := "openmole",
dockerBuildOptions += "--no-cache"
)
Note: the doMapping function fetch recursively all the resources contained in directories.
Note that my target/webapp
directory seems to be properly copied in target/docker/stage/opt/docker/target/webapp
but not in the docker itself.
The generated Docker instructions look like this:
[info] Sending build context to Docker daemon 72.6MB
[info] Step 1/22 : FROM openjdk:8 as stage0
[info] ---> b190ad78b520
[info] Step 2/22 : LABEL snp-multi-stage="intermediate"
[info] ---> Running in 9c6969995766
[info] Removing intermediate container 9c6969995766
[info] ---> 64d07a530801
[info] Step 3/22 : LABEL snp-multi-stage-id="2c8d683f-dad5-4bc2-ab11-a6f66f96bb8a"
[info] ---> Running in 27c629362891
[info] Removing intermediate container 27c629362891
[info] ---> c004389b95c2
[info] Step 4/22 : WORKDIR /opt/docker
[info] ---> Running in 9c7cd81b0f42
[info] Removing intermediate container 9c7cd81b0f42
[info] ---> 4efac068a359
[info] Step 5/22 : COPY opt /opt
[info] ---> 32c400dc8ff5
[info] Step 6/22 : COPY 1/opt /1/opt
[info] ---> 6b12f0c7b56d
[info] Step 7/22 : COPY 2/opt /2/opt
[info] ---> e6ec4c732ee5
[info] Step 8/22 : USER root
[info] ---> Running in 675f87e3b9de
[info] Removing intermediate container 675f87e3b9de
[info] ---> fa474725d20e
[info] Step 9/22 : RUN ["chmod", "-R", "u=rX,g=rX", "/opt/docker"]
[info] ---> Running in 7c8acb6e2212
[info] Removing intermediate container 7c8acb6e2212
[info] ---> 7c401cea0e70
[info] Step 10/22 : RUN ["chmod", "-R", "u=rX,g=rX", "/1/opt/docker"]
[info] ---> Running in 06214e76114c
[info] Removing intermediate container 06214e76114c
[info] ---> 9f56b46dec14
[info] Step 11/22 : RUN ["chmod", "-R", "u=rX,g=rX", "/2/opt/docker"]
[info] ---> Running in d7126964057a
[info] Removing intermediate container d7126964057a
[info] ---> 3da3628e2d99
[info] Step 12/22 : RUN ["chmod", "u+x,g+x", "/1/opt/docker/bin/application"]
[info] ---> Running in fe5c10827ff6
[info] Removing intermediate container fe5c10827ff6
[info] ---> 180fff21da6a
[info] Step 13/22 : FROM openjdk:8 as mainstage
[info] ---> b190ad78b520
[info] Step 14/22 : USER root
[info] ---> Running in 3cd3a06042d6
[info] Removing intermediate container 3cd3a06042d6
[info] ---> 96de0ebdbe78
[info] Step 15/22 : RUN id -u demiourgos728 1>/dev/null 2>&1 || (( getent group 0 1>/dev/null 2>&1 || ( type groupadd 1>/dev/null 2>&1 && groupadd -g 0 root || addgroup -g 0 -S root )) && ( type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 || adduser -S -u 1001 -G root demiourgos728 ))
[info] ---> Running in 15a57b0eb978
[info] Removing intermediate container 15a57b0eb978
[info] ---> 59a0dd3dc380
[info] Step 16/22 : WORKDIR /opt/docker
[info] ---> Running in ddc5b63af17d
[info] Removing intermediate container ddc5b63af17d
[info] ---> cd44f5ba5400
[info] Step 17/22 : COPY --from=stage0 --chown=demiourgos728:root /opt/docker /opt/docker
[info] ---> 5e256b40af0e
[info] Step 18/22 : COPY --from=stage0 --chown=demiourgos728:root /1/opt/docker /opt/docker
[info] ---> abb06e4be250
[info] Step 19/22 : COPY --from=stage0 --chown=demiourgos728:root /2/opt/docker /opt/docker
[info] ---> 915afa5d368b
[info] Step 20/22 : USER 1001:0
[info] ---> Running in db401963a3af
[info] Removing intermediate container db401963a3af
[info] ---> 7823f2903569
[info] Step 21/22 : ENTRYPOINT ["/opt/docker/bin/application"]
[info] ---> Running in ef833e26ac04
[info] Removing intermediate container ef833e26ac04
[info] ---> 0a1e5cb53cde
[info] Step 22/22 : CMD []
[info] ---> Running in 9eabe2698166
[info] Removing intermediate container 9eabe2698166
[info] ---> 8a445e1cc20a
[info] Successfully built 8a445e1cc20a
[info] Successfully tagged application:0.1.0-SNAPSHOT
[info] Removing intermediate image(s) (labeled "snp-multi-stage-id=2c8d683f-dad5-4bc2-ab11-a6f66f96bb8a")
[info] Deleted Images:
[info] deleted: sha256:180fff21da6af8d2da62373582006795770fe7ecea60b8256b7d7aa8463116c4
[info] deleted: sha256:f04603065a55aa78ace281a1af9d05e67a01a5b065c9869519805c3d3f4a5a2f
[info] deleted: sha256:3da3628e2d99ad32198bc6c679e78874ebebe84a3c1457fb1ef756b01002aa5e
[info] deleted: sha256:0a886f2e99dc51acfd17748939c9c2252e9ffe87c89e58e7cf6b868487ace60f
[info] deleted: sha256:9f56b46dec141e1210c0600e82ba1d3de1d564c2db1f0d01efac1c16d1847629
[info] deleted: sha256:e706f8706b81debe373c4e3f916bd8e97c299c9dc8487c164ef4f0b6c55af273
[info] deleted: sha256:7c401cea0e70d1a9fc2ffe9bfdb7c7ae937c47a1c648fdf38cf36b0891901fec
[info] deleted: sha256:f62020e6a514c2252f62d72956d899d18079a7377123681c4b75140d037dd1a9
[info] deleted: sha256:fa474725d20e82fbbcc726e9c67959735458f0ce7f7f2ca1894221a3b92dd649
[info] deleted: sha256:e6ec4c732ee59d5ba533636e35796564f8b5c96c0afff4a901d1a1369d74e29d
[info] deleted: sha256:a6217b39b6cdd15da3748592eb3f18a7e09778aa30cec6414fa505777972e4ee
[info] deleted: sha256:6b12f0c7b56dab95c491248ee7eeaaea58ced77e95f82d9ff5e8da6f47ae6e1b
[info] deleted: sha256:ad538d8f4a615b3c23c739f6a85d7060b2e427140d527e7576babed438932b3f
[info] deleted: sha256:32c400dc8ff5610ce1f86701ac7ddd8dfa38cc2718b781c86546aa9046bac9d2
[info] deleted: sha256:c1997359f4a8986c682a6173874b5bc98fb34b1215d3ce8473c18c4661dd8980
[info] deleted: sha256:4efac068a3596186b42f1fadec54bc920153eec51a0b0979eeab988cd1e56f28
[info] deleted: sha256:d772f376cfba48e0abc58958af608d4d7ac98f622d7be0257f49e9da94528670
[info] deleted: sha256:c004389b95c29dfefd89724448b09f77dcaa49f6da46bf0a5532ffec06613d98
[info] deleted: sha256:64d07a53080185958202592ebfd2384e80420b1b4b19ed04de6370aedcbc8e32
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
SBT native packager does not copy file to Docker image
I build a docker image of the project. The only command which does not affect the image is: ... dockerPackageMappings in Docker +=...
Read more >Volumes
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory...
Read more >Best practices for writing Dockerfiles
Omitting the build context can be useful in situations where your Dockerfile does not require files to be copied into the image, and...
Read more >docker build
docker build returns a no such file or directory error if the file or directory does not exist in the uploaded context. This...
Read more >Manage data in Docker
Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux). Non-Docker processes should not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for sharing. This is strange. The
mappings in Docker
should inherit frommappings in Universal
.The docker plugin is quite complex due to the nature of docker being complex. I’ll leave this open as there’s something weird going on, but I don’t have the time to look deeper into it 😢
Well, I fixed my problem. But I am not very sure how (and I do not like this !) I essentially changed
in Universal
inin Docker
, but it was my very initial config, which did not work. Thanks anyway !Here is the working snippet for memory: