regis-leray / sbt-docker

Create Docker images directly from Dockerfile

Version Matrix


sbt-docker is an sbt plugin that builds and pushes Docker images by using Dockerfile.


  • Sbt
  • Docker


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

addSbtPlugin("com.github.regis-leray" % "sbt-docker" % "0.4.0")

in your build.sbt need to activate manually the plugin for each project

lazy val root ="."))

Don't forget to export your DOCKER_ID_USER or DOCKER_TAG_NAMESPACE as environment variable, to be able to build and push docker image You can override dockerTagNamespace to provide it

sbt-docker is an auto plugin, this means that sbt version 0.13.5 or higher is required.

Building an image

To build an image use the dockerBuild task.

Simply run sbt dockerBuild from your prompt or dockerBuild in the sbt console.

The Dockerfile should be located at the base directory of you project ./Dockerfile

// Example if you need to override keys

lazy val root ="."))
      //override default docker image name :: default `$name`
      dockerImageName := "hello",
      //override default docker image version :: default `$version`
      dockerImageVersion := "1.0-RC",
      //override default dockerTagNamespace :: default `sys.env.get("DOCKER_ID_USER") or sys.env.get("DOCKER_TAG_NAMESPACE")`     
      dockerTagNamespace := "mycompany",
      //override default tag  :: default `$dockerTagNamespace/$dockerImageName:$dockerImageVersion`
      dockerTag := "",     
      //provide build OPTIONS :: default `Nil`
      dockerBuildOptions := Seq("--no-cache"),
      //default location of dockerfile :: default `baseDirectory`
      dockerContextPath := baseDirectory.value.asPath.resolve("docker-dir"),
      //default name of dockerfile :: default `Dockerfile`
      dockerfileName := "Dockerfile-custom"

if you need to support (private repo) only override dockerTagNamespace

lazy val root =".")) 
 .settings(dockerTagNamespace := Some(""))

How to create and push docker image on

Pushing an image

An image that have already been built can be pushed with the dockerPush task.

To push an image use the dockerPush task.

By default dockerPush will push your docker image build to dockerhub

dockerTag key is used to determine which image names to push.

// Example if you need to override keys

lazy val root ="."))
      //provide push OPTIONS :: default `Nil`
      dockerPushOptions := Seq("--disable-content-trust"),
      //override default tag `$dockerIdUserName/$name:$version`
      dockerTag := "", 

You need to be authenticated by using docker login -u $DOCKER_ID_USER, if not you can't push docker images

Building & Pushing an image

To build and push an image use the dockerBuildAndPush task.