Skip to content
Thin wrapper over docker image - manage docker images with sbt (build/push/rm/tag/...)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


sbt-docker is a thin wrapper over docker cli, for managing docker image

CircleCI codecov


  • Sbt
  • Docker Cli


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

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

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

lazy val root ="."))

sbt-docker is an auto plugin, this means that sbt version 0.13.5 or higher is required. the only dependency is on docker cli, need to be available in your PATH follow instructions here

Docker command

  • docker [OPTIONS] image push [ARGS]
  • docker [OPTIONS] image build [ARGS]
  • docker [OPTIONS] image tag [ARGS]
  • docker [OPTIONS] image rm [ARGS]

At any time you can provide docker [OPTIONS] by overriding dockerOptions property

Build an image

Simply run sbt dockerImg:build from your prompt or dockerImg:build 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 tag  :: default `${organization.value}/${name.value}:${version.value}`
      tagNames in DockerImg := Seq(""),
      //default name of dockerfile :: default `Dockerfile`
      dockerfileName in DockerImg := "Dockerfile-custom"
      //provide OPTIONS :: default `Nil`
      dockerOptions in DockerImg := Seq("--tlsverify ")     
      //provide build OPTIONS :: default `Nil`
      dockerCmdOptions in DockerImg in build := Seq("--no-cache"),
      //default location of dockerfile :: default `baseDirectory`
      buildContextPath in DockerImg in build := baseDirectory.value.asPath.resolve("docker-dir"),      

By default we are tagging the builded image (build -t) by using $organization/$name:$version as default docker image tag name, you can override, or add multiple tags by overriding tagNames

lazy val root =".")) 
 .settings(tagNames in DockerImg in build += s"${name.value}:latest")

More informations here for the build options

Tag an image

Tag an existing docker image with the dockerImg:tag task.

As source tag name we are using tagNames.head

It is required to override targetImages to provide docker target tag name,

// Example if you need to override keys

lazy val root ="."))
      //provide push OPTIONS :: default `Nil`
      targetImages in DockerImg in tag := Seq("")

Remove an image

Remove a docker image from local registry with the dockerImg:rm task. By default we are removing all the build images define by the property tagNames

// Example if you need to override keys

lazy val root ="."))
      //provide rm OPTIONS :: default `Nil`
      cmdOptions in DockerImg in rm := Seq("--no-prune"),
      //default value `dockerTagNames`
      tagNames in DockerImg in rm := Seq("")

Pushing an image

An image that have already been built can be pushed with the dockerImg:push task.

By default dockerImg:push will push your docker image tags define by the tagNames property but you can still override

tagNames 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`
      cmdOptions in DockerImg in push := Seq("--disable-content-trust"),
      tagNames in DockerImg in push := Seq("")

With docker push you can specify which image to push by overriding settings tagNames in DockerImg in push, it will only apply this settings for the task push

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

You can’t perform that action at this time.