sbt-docker alternatives and similar packages
Based on the "Sbt plugins" category.
Alternatively, view sbt-docker alternatives based on common mentions on social networks and blogs.
-
sbt-assembly
Deploy über-JARs. Restart processes. (port of codahale/assembly-sbt) -
sbt-dependency-graph
sbt plugin to create a dependency graph for your project -
sbt-jmh
"Trust no one, bench everything." - sbt plugin for JMH (Java Microbenchmark Harness) -
sbt-revolver
An SBT plugin for dangerously fast development turnaround in Scala -
sbt-updates
sbt plugin that can check Maven and Ivy repositories for dependency updates -
better-monadic-for
Desugaring scala `for` without implicit `withFilter`s -
sbt-mima-plugin
A tool for catching binary incompatibility in Scala -
sbt-microsites
An sbt plugin to create awesome microsites for your project -
sbt-ensime
Generates .ensime config files for SBT projects http://ensime.org/build_tools/sbt -
sbt-sonatype
A sbt plugin for publishing Scala/Java projects to the Maven central. -
sbt-ci-release
sbt plugin to automate Sonatype releases from GitHub Actions -
sbt-dependency-check
SBT Plugin for OWASP DependencyCheck. Monitor your dependencies and report if there are any publicly known vulnerabilities (e.g. CVEs). :rainbow: -
sbt-header
sbt-header is an sbt plugin for creating file headers, e.g. copyright headers -
sbt-play-scalajs
SBT plugin to use Scala.js along with any sbt-web server. -
sbt-api-mappings
An Sbt plugin that fills apiMappings for common Scala libraries. -
sbt-unidoc
sbt plugin to create a unified Scaladoc or Javadoc API document across multiple subprojects. -
sbt-sublime
An sbt plugin for generating Sublime Text projects with library dependencies sources -
sbt pom reader plugin
Translates xml -> awesome. Maven-ish support for sbt. -
sbt-ide-settings
SBT plugin for tweaking various IDE settings -
sbt-scala-js-map
A Sbt plugin that configures source mapping for Scala.js projects hosted on Github -
sbt-versions
Plugin that checks for updated versions of your project's dependencies. -
sbt-hepek
Sbt plugin for rendering Scala objects to files. And more! -
sbt-pantarhei
sbt plugin building and publishing release notes from github pull requests -
sbt-classfinder
SBT plugin for retrieving runtime information about the classes and traits in a project
Access the most powerful time series database as a service
Do you think we are missing an alternative of sbt-docker or a related project?
README
sbt-docker
sbt-docker is an sbt plugin that builds and pushes Docker images for your project.
Requirements
- sbt
- Docker
Setup
Add sbt-docker as a dependency in project/plugins.sbt
:
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.8.2")
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](examples).
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](examples/DockerfileExamples.scala) for different ways of defining a Dockerfile.
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.
Example:
docker / buildOptions := BuildOptions(
cache = false,
removeIntermediateContainers = BuildOptions.Remove.Always,
pullBaseImage = BuildOptions.Pull.Always,
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.
Auto packaging JVM applications
If you have a standalone JVM application that you want a simple Docker image for.
Then you can use dockerAutoPackageJavaApplication(fromImage, exposedPorts, exposedVolumes, username)
which will setup some settings for you, including a Dockerfile.
Its very basic, so if you have more advanced needs then define your own Dockerfile.