Coder Social home page Coder Social logo

sbt-docker's Introduction

sbt-docker

sbt-docker is an sbt plugin that builds and pushes Docker images for your project.

Build Status Maven Central

Requirements

  • sbt
  • Docker

Setup

Add sbt-docker as a dependency in project/plugins.sbt:

addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.9.0")

Getting started

Below are some documentation on the sbt tasks and settings in the plugin.

This blog post gives a good introduction to the basics of sbt-docker: Dockerizing your Scala apps with sbt-docker

Also, take a look at the example projects.

Usage

Start by enabling the plugin in your build.sbt file:

enablePlugins(DockerPlugin)

This sets up some settings with default values and adds tasks such as docker which builds a Docker image. The only required setting that is left to define is docker / dockerfile.

Artifacts

If you want your Dockerfile to contain one or several artifacts (such as JAR files) that your project generates, then you must make the docker task depend on the tasks that generate them. It could for example be with the package task or with tasks from plugins such as sbt-assembly.

Defining a Dockerfile

In order to produce a Docker image a Dockerfile must be defined. It should be defined at the docker / dockerfile key. There is a mutable and an immutable Dockerfile class available, both provides a DSL which resembles the plain text Dockerfile format. The mutable class is default and is used in the following examples.

Example with the sbt-assembly plugin:

docker / dockerfile := {
  // The assembly task generates a fat JAR file
  val artifact: File = assembly.value
  val artifactTargetPath = s"/app/${artifact.name}"

  new Dockerfile {
    from("openjdk:8-jre")
    add(artifact, artifactTargetPath)
    entryPoint("java", "-jar", artifactTargetPath)
  }
}

Example with sbt-native-packager:

enablePlugins(sbtdocker.DockerPlugin, JavaAppPackaging)

docker / dockerfile := {
  val appDir: File = stage.value
  val targetDir = "/app"

  new Dockerfile {
    from("openjdk:8-jre")
    entryPoint(s"$targetDir/bin/${executableScriptName.value}")
    copy(appDir, targetDir, chown = "daemon:daemon")
  }
}

Example with the sbt package task.

docker / dockerfile := {
  val jarFile: File = (Compile / packageBin / sbt.Keys.`package`).value
  val classpath = (Compile / managedClasspath).value
  val mainclass = (Compile / packageBin / mainClass).value.getOrElse(sys.error("Expected exactly one main class"))
  val jarTarget = s"/app/${jarFile.getName}"
  // Make a colon separated classpath with the JAR file
  val classpathString = classpath.files.map("/app/" + _.getName)
    .mkString(":") + ":" + jarTarget
  new Dockerfile {
    // Base image
    from("openjdk:8-jre")
    // Add all files on the classpath
    add(classpath.files, "/app/")
    // Add the JAR file
    add(jarFile, jarTarget)
    // On launch run Java with the classpath and the main class
    entryPoint("java", "-cp", classpathString, mainclass)
  }
}

Example with a Dockerfile in the filesystem.

docker / dockerfile := NativeDockerfile(file("subdirectory") / "Dockerfile")

Have a look at DockerfileExamples for different ways of defining a Dockerfile.

Missing Dockerfile instructions

Dockerfile instructions that are missing from the sbt-docker DSL can still be used by calling the .customInstruction(instructionName, arguments) method. Example:

new Dockerfile {
  customInstruction("FROM", "openjdk AS stage1")
  run("build")

  customInstruction("FROM", "openjdk AS stage2")
  customInstruction("COPY", "--from=stage1 /path/to/file /path/to/file")
  customInstruction("STOPSIGNAL", "SIGQUIT")
  
  entryPoint("application")
}

Building an image

To build an image use the docker task. Simply run sbt docker from your prompt or docker in the sbt console.

Pushing an image

An image that have already been built can be pushed with the dockerPush task. To both build and push an image use the dockerBuildAndPush task.

The docker / imageNames key is used to determine which image names to push.

Custom image names

You can specify the names / tags you want your image to get after a successful build with the docker / imageNames key of type Seq[sbtdocker.ImageName].

Example:

docker / imageNames := Seq(
  // Sets the latest tag
  ImageName(s"${organization.value}/${name.value}:latest"),

  // Sets a name with a tag that contains the project version
  ImageName(
    namespace = Some(organization.value),
    repository = name.value,
    tag = Some("v" + version.value)
  )
)

Build options

Use the key docker / buildOptions to set build options.

cross-platform

The platforms parameter enables the cross-platform build. With valuing this parameter the docker image will build using buildx command and the host environment should already been set up for.

โš ๏ธ For using the cross builds you need QEMU binaries

docker run --privileged --rm tonistiigi/binfmt --install all

Example:

docker / buildOptions := BuildOptions(
  cache = false,
  removeIntermediateContainers = BuildOptions.Remove.Always,
  pullBaseImage = BuildOptions.Pull.Always,
  platforms = List("linux/arm64/v8"),
  additionalArguments = Seq("--add-host", "127.0.0.1:12345", "--compress")
)

Build arguments

Use the key docker / dockerBuildArguments to set build arguments.

Example:

docker / dockerBuildArguments := Map(
  "KEY" -> "value",
  "CREDENTIALS" -> sys.env("CREDENTIALS")
)

docker / dockerfile := {
  new Dockerfile {
    // ...
    arg("KEY")
    arg("CREDENTIALS")
    env("KEY" -> "$KEY", "CREDENTIALS" -> "$CREDENTIALS")
    // ...
  }
}

BuildKit support

Images can be built with BuildKit by enabling it in the daemon configuration or by passing the environment variable DOCKER_BUILDKIT=1 to sbt.

sbt-docker's People

Contributors

alexgaribay avatar argoyle avatar aszczepanik avatar colindean avatar giabao avatar imants-ltq avatar japgolly avatar jiminhsieh avatar kurtkopchik avatar lamdor avatar marcuslonnberg avatar matlockx avatar n4to4 avatar nik-kashi avatar olofwalker avatar peterbecich avatar softprops avatar sullis avatar szczepanja avatar viktortnk avatar williammmeyer avatar xperimental avatar yuchaoran2011 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-docker's Issues

How to copy file from main dir

Hi,

how do I copy a file from the main dir (same as build.sbt) to the docker container?

dockerfile in docker := {
  val artifact: File = assembly.value
  val artifactTargetPath = s"/app/${artifact.name}"
  new Dockerfile {
    from("java:openjdk-8u91-jre")
    add(artifact, artifactTargetPath)
    addRaw("production.conf","/app/production.conf")
    entryPoint("java", "-jar","-Dconfig.resource=/app/production.conf", artifactTargetPath)
  }
}

returns the error

[info] Step 3 : ADD production.conf /app/production.conf
[info] lstat production.conf: no such file or directory

run and runShell?

Hi,

What is the difference between run and runShell?

I tried:

  • runShell("mkdir /app") failed
  • run("mkdir /app") failed
  • run("mkdir", "/app") succeed

I guess is the same philosophy with entryPoint

CopyFile.stage does not preserve execute permissions

When adding or staging files, set execute permissions (e.g., chmod u+x-like settings) are not preserved. This is because sbt.IO's copyFile method just copies file content. While there is a flag to preserve the last modified timestamp, nothing similar exists for execute permissions. For binaries/scripts copied into the Docker image, this is a problem.

I found sbt upstream issue #713 which addresses the issue. Unfortunately, the ticket has been marked as duplicate with no reference to the official issue, and I failed to find any other as well. Thus, I think it'd be best if sbt-docker would swap out the copy implementation by something that keeps execute permissions.

First release?

Nice plugin!

When do you plan to release a version of the sbt-docker plugin?
I'm using it but due to the code changes last weekend my sbt build was broken.

possibility to update latest tag when executing docker command

The sbt-native-packager provides a setting called dockerUpdateLatest which automatically updates the latest tag. Is there a way to simulate that behavior with your plugin?

For example, right now on my project I have something like:

imageNames in docker := Seq(
    ImageName(
        namespace = Some(organization.value),
        repository = name.value,
        tag = Some(version.value)
    )
)

that will generate the image with the corresponding version taken from the version value on the sbt file.

How can I "tell" the plugin to also generate/update the "latest" tag?

Thanks!

Error building image

Hello,

I write this issue because I haven't found any solution in the net.

I've been trying to pack my play app in a docker container using sbt-docker and the docker task is failing. Right after the plugin starts docker I get the trace before. Maybe the is the plugin incompatible with my docker version? I'm using "se.marcuslonnberg" % "sbt-docker" % "1.3.0" and sbt 0.13.9.

Thanks in advance,
Antonio.

[debug] Building Dockerfile:
[debug] FROM frolvlad/alpine-oraclejdk8:slim
[debug] COPY 0/stage /app
[debug] ENTRYPOINT ["/app/stage/bin/server"]
[debug] EXPOSE 9000 2549
[debug] Preparing stage directory '/home/antonio/Dropbox/sparkmind_code/sparkmind-web/server/target/docker'
[debug] Running command: 'docker build --no-cache=false --rm=true --pull=false .' in '/home/antonio/Dropbox/sparkmind_code/sparkmind-web/server/target/docker'
[info] docker - version 1.4
[info] Copyright 2003, Ben Jansens [email protected]
[info]
[info] Usage: docker [OPTIONS]
[info]
[info] Options:
[info] -help Show this help.
[info] -display DISPLAY The X display to connect to.
[info] -border The width of the border to put around the
[info] system tray icons. Defaults to 1.
[info] -vertical Line up the icons vertically. Defaults to
[info] horizontally.
[info] -wmaker WindowMaker mode. This makes docker a
[info] fixed size (64x64) to appear nicely in
[info] in WindowMaker.
[info] Note: In this mode, you have a fixed
[info] number of icons that docker can hold.
[info] -iconsize SIZE The size (width and height) to display
[info] icons as in the system tray. Defaults to
[info] 24.
[info] -color COLOR The background color to use for the tray.
[info] Defaults to whatever color the window
[info] manager specifies.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.process.BasicIO$Streamed$.scala$sys$process$BasicIO$Streamed$$next$1(BasicIO.scala:48)
at scala.sys.process.BasicIO$Streamed$$anonfun$scala$sys$process$BasicIO$Streamed$$next$1$1.apply(BasicIO.scala:49)
at scala.sys.process.BasicIO$Streamed$$anonfun$scala$sys$process$BasicIO$Streamed$$next$1$1.apply(BasicIO.scala:49)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1085)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1077)
at scala.collection.immutable.Stream.foreach(Stream.scala:548)
at sbtdocker.DockerBuild$.build(DockerBuild.scala:87)
at sbtdocker.DockerBuild$.buildAndTag(DockerBuild.scala:72)
at sbtdocker.DockerBuild$.apply(DockerBuild.scala:45)
at sbtdocker.DockerBuild$.apply(DockerBuild.scala:24)
at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:17)
at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:10)

possiblity to generate just the dockerfile and artifacts and change the default route

Hi! Couple of silly questions:

  1. Is there a way to configure the plugin to just generate the dockerfile and the artifacts (all the .jar files under /target/docker) and not creating the image in my local machine (due to space limitations) whenever I run the "sbt docker" command?

  2. Is there a way to change the default path of the artifacts "[app-root]/target/docker" to lets say, just "[app-root]/docker"?

Thanks :)

dockerPush doesn't show incremental progress

When I use dockerPush, I just get series of lines showing nothing but [info] where the docker CLI tool would normally show the progress of the push.

[conspire] (docker) $ node:dockerPush
[info] Pushing docker image with name: 'conspire/node:docker'
[info] The push refers to a repository [conspire/node] (len: 1)
[info] Sending image list
[info] Pushing repository conspire/node (1 tags)
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] 
[info] Pushing tag for rev [0b6d4454578f] on {https://cdn-registry-1.docker.io/v1/repositories/conspire/node/tags/docker}
[success] Total time: 125 s, completed Sep 23, 2014 10:59:23 AM

Building the docker image does show each step in the Dockerfile. Is there a setting that controls this?

env() command escapes incorrectly

For example, if you use env("JAVA_OPTS" -> "-Dconfig.resource=docker.conf") the resulting env-variable JAVA_OPTS will have the value -Dconfig.resource\=docker.conf. Note the backslash

java.lang.RuntimeException: Could not parse Version from 17.03.0-ce

java.lang.RuntimeException: Could not parse Version from 17.03.0-ce
: `.' expected but `3' found
        at sbtdocker.DockerVersion$.parseVersion(DockerVersion.scala:26)
        at sbtdocker.DockerVersion$.apply(DockerVersion.scala:20)
        at sbtdocker.DockerTag$.apply(DockerTag.scala:17)
        at sbtdocker.DockerBuild$$anonfun$buildAndTag$1.apply(DockerBuild.scala:75)
        at sbtdocker.DockerBuild$$anonfun$buildAndTag$1.apply(DockerBuild.scala:74)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at sbtdocker.DockerBuild$.buildAndTag(DockerBuild.scala:74)
        at sbtdocker.DockerBuild$.apply(DockerBuild.scala:45)
        at sbtdocker.DockerBuild$.apply(DockerBuild.scala:24)
        at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:17)
        at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:10)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

Dokerfile

Hi, I have a question,
I use sbt+docker and by default, have dokerfile:

FROM java
WORKDIR /opt/docker
ADD opt /opt
RUN ["chown", "-R", "daemon:daemon", "."]
USER daemon
ENTRYPOINT ["bin/script_name"]
CMD []

How to modify "ENTRYPOINT ["bin/script_name"]" section to "ENTRYPOINT ["bin/script_name -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999"] "

I tryed add to build.sbt a line "dockerEntrypoint := "/bin/script_name -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999"", but had no result

Thanks

Docker task fails with latest Docker for OSX

When running current Docker version (17.03.0-ce) on OSX, the following errors shows up when running the docker task:

[error] (awesome_software/*:docker) Could not parse Version from 17.03.0-ce
[error] : `.' expected but `3' found

This is most probably caused by new version format, introduced together with Docker Community Edition (whatever this means).

Configure dockerPush to use a private registry instead of docker.io

Currently to push to a private repository, I append the registry in frontend of the images name like:
myregistry/project1/target1:version. It will be useful to have an option to configure the registry to push to (that is appended in front of the name at time of push).
This problem could also be solved by allowing multiple tags based upon some settings( for example registry ) and allowing to push only the selected tag(s). For example:
ImageName("localRegistry",s"$dockerRegistry/$project/$name:v${version.value}"),
ImageName("default",s"$project/$name:v${version.value}")

and then allowing
sbt target/dockerBuildAndPush localRegistry

sudo

on linux, the task docker fails because it's not run as root

[info] time="2015-03-19T16:12:18-04:00" level="fatal" msg="Post http:///var/run/docker.sock/v1.17/build?dockerfile=Dockerfile&rm=1&t=: dial unix /var/run/docker.sock: permission denied" 
[info] Sending build context to Docker daemon 

Docs for depending on package task causes sbt import error

Hello! Thanks for the project. Saved me from writing bash.

I lost some time on using the docs for depending on the package task. Specifically, docker <<= docker.dependsOn(package.in(Compile, packageBin)) throws an error:

Error:Error while importing SBT project:

[info] Loading project definition from /home/brandon/src/coins/kafka-cryptocoin/project
/home/brandon/src/coins/kafka-cryptocoin/docker.sbt:1: error: reference to package is ambiguous;
it is imported twice in the same scope by
import dsl._
and import Keys._
docker <<= docker.dependsOn(`package`.in(Compile, packageBin))
                            ^
[error] Type error in expression

The basic example worked fine. So, I followed it. Can we change the docs to follow the basic example? Confirm this, and I'll send a PR.

Cannot find or load main class Docker

Hey there,

not sure, if it belongs here, but i got an issue, that when i pack my Akka project into a docker image, it cannot find the main class when running the docker image. Are there any known problems like this or workarounds?

Thanks in advance!

CHANGELOG stuck at 1.0.0

While I do see updates in the notes/ directory, they don't seem to be reflected in the CHANGELOG anymore: The latest entry is for 1.0.0.

Can we possibly bring the CHANGELOG up-to-date?

Thanks!

Multi-modules SBT project support

Support for multi-module projects would be nice. Or, if it is already supported, how do I use it?

I tried dockerfile in docker in ThisBuild but it didn't work.
I also tried to add it to the project settings like:

lazy val myProject = Project("myProject", file("myProject")
    .settings(
      dockerfile in docker := { ... }
    )

But it didn't work either.

Support ADDing to directory, not just specifying file

The add(src: File, dest: String) command rewrites the 'dest' parameter. I'm not sure why it does this, but it has the side-effect, as of 1.1.0, of not decompressing tar files on ADD.

In 1.0.1, you could have this:
ADD foo.tgz /foo.tgz

and Docker would expand foo.tgz at root.

In 1.1.0, that behavior has been tightened up a bit. If you want the auto-expand, you have to add to a directory:
ADD foo.tgz /

Yet, sbt-docker does not seem to allow that. If you try and have a 'to' that ends in a slash, it adds the filename in.

Push image with specific ImageName

I declare 2 ImageName, one with version and one with "latest" tag. Sometimes I want to push only one specific ImageName (with version).

2.11 Release

It would be nice to have a release out for 2.11. I'm trying to get this project to cross build. If ti works out I'll open a PR.

Integrate docker login for private repositories

We push to a private registry (i.e. on dockerhub but private) so before we can do a docker push, we need to call docker login. It would be great if this plugin would support this.

Suggested solution:

  • create a DockerRegistry case class instead of the String currently used in ImageName and add a private boolean and an optional credentials field
  • update DockerPush to perform the necessary docker login command for private registries
  • (optionally) update DockerPush to perform the docker logout command afterwards

I'll probably start building this very soon since our project needs these features so if you agree with the suggested solution, I'll send you a pull request next week.

Regards,
Age

Private registry

Hi all -

Is there a way to push to private registries using sbt-docker?

Timeout on docker push

Hey,

I'm using docker 1.9.1 and tried sbt-docker 1.2.0 & 1.3.0 and since yesterday I always get this error, I tried like 50 times, but pushing the image directly by docker push works every time... Any idea why does it happen only when using sbt-docker ?

[info] Head https://registry-1.docker.io/v2/gwiq/gwiq-app/blobs/sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4: dial tcp 54.209.64.176:443: i/o timeout
java.lang.RuntimeException: Failed to push
        at scala.sys.package$.error(package.scala:27)
        at sbtdocker.DockerPush$.apply(DockerPush.scala:42)
        at sbtdocker.DockerPush$$anonfun$apply$1.apply(DockerPush.scala:17)
        at sbtdocker.DockerPush$$anonfun$apply$1.apply(DockerPush.scala:16)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at sbtdocker.DockerPush$.apply(DockerPush.scala:16)
        at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$2.apply(DockerSettings.scala:24)
        at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$2.apply(DockerSettings.scala:19)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:235)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

define an immutable dockerfile

I don't think this would be hard but its a change to the interface. The current interface kind resembles authorizing a docker files output ( which I really like )

new Dockerfile {
   from("dockerfile/java")
   xxx("...")
}

It would be cool to about to reuse a setting and modify/append to it in someway which lends it self towards an immutable builder of sorts

val a = Dockerfile.empty
  .from("dockerfile/java")
  .xxx("...")

val b = a.from("other/image")

ect

Not sure if it makes sense to support both a mutable and immutable version

http: server gave HTTP response to HTTPS client

docker version: ....... 1.12.1, build 23cf638
sbt-docker version: ... 1.4.0
sbt version: .......... 0.13.11
scala version: ........ 2.11.7
java version: ......... openjdk "1.8.0_91"
os: ................... Ubuntu 16.04.1 LTS

I'm currently trying to build and push an image to a plain HTTP registry.
I've followed the instructions provided here to do so but the following error occurs when running sbt dockerBuildAndPush (strings within braces have been redacted):

[info] Successfully built {SHA}
[info] Tagging image {SHA} with name: {REG}/{NS}/{IMAGE}:{TAG1}
[info] Tagging image {SHA} with name: {REG}/{NS}/{IMAGE}:{TAG2}
[info] Tagging image {SHA} with name: {REG}/{NS}/{IMAGE}:{TAG3}
[info] Pushing docker image with name: '{REG}/{NS}/{IMAGE}:{TAG1}
[info] The push refers to a repository [{REG}/{NS}/{IMAGE}]
[info] Get https://{REG}/v1/_ping: http: server gave HTTP response to HTTPS client
java.lang.RuntimeException: Failed to push
    at scala.sys.package$.error(package.scala:27)
    at sbtdocker.DockerPush$.apply(DockerPush.scala:42)
    at sbtdocker.DockerPush$$anonfun$apply$1.apply(DockerPush.scala:17)
    at sbtdocker.DockerPush$$anonfun$apply$1.apply(DockerPush.scala:16)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at sbtdocker.DockerPush$.apply(DockerPush.scala:16)
    at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$2.apply(DockerSettings.scala:24)
    at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$2.apply(DockerSettings.scala:19)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Provide exit code for dockerBuildAndPush task

I run the sbt dockerBuildAndPush task as part of a continuous integration workflow and notice that no exit code is provided by the task. I would expect a 0 exit code if the build and push completed successfully and a non-zero exit code to signify a failure (of either the building or pushing of the image).

DockerVersion parse exception for the latest docker version 17.03.0-ce

per title.

java.lang.RuntimeException: Could not parse Version from 17.03.0-ce
: `.' expected but `3' found
        at sbtdocker.DockerVersion$.parseVersion(DockerVersion.scala:26)
        at sbtdocker.DockerVersion$.apply(DockerVersion.scala:20)
        at sbtdocker.DockerTag$.apply(DockerTag.scala:17)
        at sbtdocker.DockerBuild$$anonfun$buildAndTag$1.apply(DockerBuild.scala:75)
        at sbtdocker.DockerBuild$$anonfun$buildAndTag$1.apply(DockerBuild.scala:74)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at sbtdocker.DockerBuild$.buildAndTag(DockerBuild.scala:74)
        at sbtdocker.DockerBuild$.apply(DockerBuild.scala:45)
        at sbtdocker.DockerBuild$.apply(DockerBuild.scala:24)
        at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:17)
        at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:10)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[error] (api/*:docker) Could not parse Version from 17.03.0-ce
[error] : `.' expected but `3' found

tag for version 1.0.0 missing

It seems like version 1.0.0 of the plugin was released a few days ago (maven.org link). However, a corresponding git tag is missing for that release; the latest that can be found is still 0.5.2.

Could you add and push the tag so that looking up the code for a particular version in git is possible?

Thanks.

Error when building Dockerfile

Hi,
Thank you for this very useful tool
After the docker container is built and I get the message "Successfully built .... " I get this message
[info] Removing intermediate container .....................
java.lang.RuntimeException: Error when building Dockerfile
at scala.sys.package$.error(package.scala:27)
at sbtdocker.DockerBuilder$.buildImage(DockerBuilder.scala:87)
at sbtdocker.DockerBuilder$.apply(DockerBuilder.scala:23)
at sbtdocker.Plugin$$anonfun$baseDockerSettings$1.apply(Plugin.scala:27)
at sbtdocker.Plugin$$anonfun$baseDockerSettings$1.apply(Plugin.scala:22)
at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
error Error when building Dockerfile

build marked as error when it's actually successful

I'm seeing the following:

[info] Successfully built :hash1
[info] Removing intermediate container :hash2
java.lang.RuntimeException: Could not parse image id
    at scala.sys.package$.error(package.scala:27)
    at sbtdocker.DockerBuilder$.buildImage(DockerBuilder.scala:87)
    at sbtdocker.DockerBuilder$.apply(DockerBuilder.scala:23)
    at sbtdocker.Plugin$$anonfun$baseDockerSettings$1.apply(Plugin.scala:27)
    at sbtdocker.Plugin$$anonfun$baseDockerSettings$1.apply(Plugin.scala:22)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
[error] (*:docker) Could not parse image id

Looks like the code to parse the image id fails if there's a "removing intermediate container" line after "successfully built" since it only looks at the very last line of output: https://github.com/marcuslonnberg/sbt-docker/blob/master/src/main/scala/sbtdocker/DockerBuilder.scala#L82

I'm only seeing this transiently.

Problems with docker 1.17.0-ce

The plugin has problems with the latest docker releases, as they report a version in the format "1.17.0-ce", which cannot be parsed by the Regex in Docker-Version:

https://github.com/marcuslonnberg/sbt-docker/blob/2bb33d1b4525b60c0b0151ac0bb2a706b3c399ea/src/main/scala/sbtdocker/DockerVersion.scala

The regex assumes a version in the format 1.13.0 (three whole numbers), but the new releases seem to add a -ce to the end, which breaks all builds on the current version.

dockerBuildAndPush starts the app

I'm not 100% sure about this, but it seems that when I run sbt dockerBuildAndPush the application starts. But if I runsbt docker && sbt dockerPush the app will not start. Is this correct? Is it intentional?

Passing arguments using entryPointShell broken

Hi,

I cannot find a way how to properly pass arguments using entryPointShell. For instance :

entryPointShell("java", "-jar", "my.jar", "$@")
docker run --rm my-image foo bar baz

Looses the first foo argument, only bar baz come through.

entryPointShell("java", "-jar", "my.jar")
docker run --rm my-image foo bar baz

Doesn't pass any argument at all.

I tried many more other combinations but nothing does it. Could you please help me out here? Note that I need shell here cause I'm passing also env variables in there.

var in from instruction

When using a var in from instruction in a Build.scala file, the var isn't replaced by its value.

e.g from("java:${javaVersion}") will end in
[info] Step 1 : FROM java:${javaVersion}

Is it the expected behaviour?

Thanks,
Pierre.

docker task doesn't respect configuration scopes

... or so it seems.

Background: I'm writing a SBT plugin for developers to run project's SBT session inside Docker container. This is needed because our application needs a specific Linux environment, and some developers use OSX. Something like Vagrant. I also want to package the application to a Docker image for deployment. Docker image for development and for publishing are different. I want to use sbt-docker for both of these tasks.

But when I want to scope dockerfile setting a config other than Global, I run into this issue. If I define dockerfile in docker only inside some specific configuration, I can't build the image. I get the following error:

(*:docker::dockerfile) A Dockerfile is not defined. Please define one with `dockerfile in docker`

even though I have the following settings in my plugin:

object autoImport {
  lazy val prepareDevContainer = taskKey[String]("Prepares a Docker image to run the SBT session in")
  lazy val devContainerConfig = config("devcontainer") extend(Compile)
}

private lazy val devContainerSettings = Seq(
    dockerfile in docker := createDevDockerfile(), // details elided
    prepareDevContainer := {
      val port = play.PlayImport.PlayKeys.playDefaultPort.value
      s"docker run -it -p $port:$port -v ${ivyPaths.value.ivyHome.get}:/tmp/.ivy2 " +
        s"-v ${System.getProperty("user.home")}/.aws/config:/root/.aws/config " +
        s"-v ${baseDirectory.value.getParent}:/src ${DockerKeys.docker.value.id} " +
        "/bin/sh -c \"cd application; sbt -Dsbt.ivy.home=/tmp/.ivy2 -Divy.home=/tmp/.ivy2\""
    },
    imageNames in docker := Seq(ImageName("sbt-centos7")))

override def projectSettings: Seq[Def.Setting[_]] = 
  inConfig(devContainerConfig)(devContainerSettings)

If I change the projectSettings definitions to the following:

override def projectSettings: Seq[Def.Setting[_]] = 
  inConfig(devContainerConfig)(devContainerSettings) ++ Seq(
    dockerfile in docker := createProdDockerfile())

then I can build the image, but I can't use different dockerfiles for dev and production, and createProdDockerfile() value is always used.

In other words, in sbt console show docker::dockerfile and show devcontainer:docker::dockerfile correctly give different output, but executing devcontainer:docker incorrectly produce the same image as just docker.

New Version of Docker for Mac Breaks Version Check

Getting the following after upgrading to Docker for Mac CE (they changed the name ๐Ÿ™„ )...

java.lang.RuntimeException: Could not parse Version from 17.03.0-ce
: `.' expected but `3' found
	at sbtdocker.DockerVersion$.parseVersion(DockerVersion.scala:26)
	at sbtdocker.DockerVersion$.apply(DockerVersion.scala:20)
	at sbtdocker.DockerTag$.apply(DockerTag.scala:17)
	at sbtdocker.DockerBuild$$anonfun$buildAndTag$1.apply(DockerBuild.scala:75)
	at sbtdocker.DockerBuild$$anonfun$buildAndTag$1.apply(DockerBuild.scala:74)
	at scala.collection.immutable.List.foreach(List.scala:318)
	at sbtdocker.DockerBuild$.buildAndTag(DockerBuild.scala:74)
	at sbtdocker.DockerBuild$.apply(DockerBuild.scala:45)
	at sbtdocker.DockerBuild$.apply(DockerBuild.scala:24)
	at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:17)
	at sbtdocker.DockerSettings$$anonfun$baseDockerSettings$1.apply(DockerSettings.scala:10)
	at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
	at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
	at sbt.std.Transform$$anon$4.work(System.scala:63)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.Execute.work(Execute.scala:237)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
	at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[error] (*:docker) Could not parse Version from 17.03.0-ce
[error] : `.' expected but `3' found
[error] Total time: 106 s, completed Mar 2, 2017 10:16:52 AM

I checked out the version parsing code, I'll see if I can whip up a fix.

EDIT: I should add, this is under sbt-docker v 1.4.0

classpath issue with dockerSettingsAutoPackage ?

Hi,

First, thumbs up! I've just discovered sbt-docker and I love the idea and simplicity!

Now I've tried packaging a little spray application with

    dockerSettingsAutoPackage("dockerfile/java", Seq(8080))

It creates the image without error, but when I try to run it, I get a NoClassDefFoundError.
And "docker inspect" shows this:

    "Entrypoint": [
        "java",
        "-cp",            "/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/libs:/app/server_2.11-0.1.jar",
        "ap.test.Server"
    ],

It looks like the artifact names are missing from the classpath.

Note: I've also tried copying the sample from package-spray, but sbt complains on:

    error: not found: value docker
    docker <<= docker.dependsOn(Keys.`package`.in(Compile, packageBin))

thanks for the support .. and sorry if i'm doing something obviously wrong!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.