{"id":26643536,"url":"https://github.com/marcuslonnberg/sbt-docker","last_synced_at":"2025-03-24T20:02:11.605Z","repository":{"id":13166336,"uuid":"15849295","full_name":"marcuslonnberg/sbt-docker","owner":"marcuslonnberg","description":"Create Docker images directly from sbt","archived":false,"fork":false,"pushed_at":"2024-07-18T07:59:11.000Z","size":420,"stargazers_count":729,"open_issues_count":29,"forks_count":109,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-07-31T21:57:11.506Z","etag":null,"topics":["docker","sbt","sbt-docker","sbt-plugin","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcuslonnberg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-01-12T19:43:03.000Z","updated_at":"2024-05-30T07:11:33.000Z","dependencies_parsed_at":"2024-06-19T00:26:59.844Z","dependency_job_id":"99da8a4c-2d72-4b3f-8f39-6e4f7a5b41c2","html_url":"https://github.com/marcuslonnberg/sbt-docker","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuslonnberg%2Fsbt-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuslonnberg%2Fsbt-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuslonnberg%2Fsbt-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuslonnberg%2Fsbt-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcuslonnberg","download_url":"https://codeload.github.com/marcuslonnberg/sbt-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245343997,"owners_count":20599867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","sbt","sbt-docker","sbt-plugin","scala"],"created_at":"2025-03-24T20:01:59.842Z","updated_at":"2025-03-24T20:02:11.580Z","avatar_url":"https://github.com/marcuslonnberg.png","language":"Scala","readme":"sbt-docker\n==========\n\nsbt-docker is an [sbt][sbt] plugin that builds and pushes [Docker][docker] images for your project.\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/se.marcuslonnberg/sbt-docker/badge.svg)](https://maven-badges.herokuapp.com/maven-central/se.marcuslonnberg/sbt-docker)\n\nRequirements\n------------\n\n* sbt\n* Docker\n\nSetup\n-----\n\nAdd sbt-docker as a dependency in `project/plugins.sbt`:\n\n```text\naddSbtPlugin(\"se.marcuslonnberg\" % \"sbt-docker\" % \"1.11.0\")\n```\n\n### Getting started\n\nBelow are some documentation on the sbt tasks and settings in the plugin.\n\nThis blog post gives a good introduction to the basics of sbt-docker: [Dockerizing your Scala apps with sbt-docker][dockerizing-scala-apps]\n\nAlso, take a look at the [example projects](examples).\n\nUsage\n-----\n\nStart by enabling the plugin in your `build.sbt` file:\n```scala\nenablePlugins(DockerPlugin)\n```\n\nThis sets up some settings with default values and adds tasks such as `docker` which builds a Docker image.\nThe only required setting that is left to define is `docker / dockerfile`.\n\n### Artifacts\n\nIf you want your Dockerfile to contain one or several artifacts (such as JAR files) that your\nproject generates, then you must make the `docker` task depend on the tasks that generate them.\nIt could for example be with the `package` task or with tasks from plugins such as\n[sbt-assembly][sbt-assembly].\n\n### Defining a Dockerfile\n\nIn order to produce a Docker image a Dockerfile must be defined.\nIt should be defined at the `docker / dockerfile` key.\nThere is a mutable and an immutable Dockerfile class available, both provides a DSL which resembles\nthe plain text [Dockerfile] format.\nThe mutable class is default and is used in the following examples.\n\nExample with the [sbt-assembly][sbt-assembly] plugin:\n```scala\ndocker / dockerfile := {\n  // The assembly task generates a fat JAR file\n  val artifact: File = assembly.value\n  val artifactTargetPath = s\"/app/${artifact.name}\"\n\n  new Dockerfile {\n    from(\"openjdk:8-jre\")\n    add(artifact, artifactTargetPath)\n    entryPoint(\"java\", \"-jar\", artifactTargetPath)\n  }\n}\n```\n\nExample with [sbt-native-packager][sbt-native-packager]:\n```scala\nenablePlugins(sbtdocker.DockerPlugin, JavaAppPackaging)\n\ndocker / dockerfile := {\n  val appDir: File = stage.value\n  val targetDir = \"/app\"\n\n  new Dockerfile {\n    from(\"openjdk:8-jre\")\n    entryPoint(s\"$targetDir/bin/${executableScriptName.value}\")\n    copy(appDir, targetDir, chown = \"daemon:daemon\")\n  }\n}\n```\n\nExample with the sbt `package` task.\n```scala\ndocker / dockerfile := {\n  val jarFile: File = (Compile / packageBin / sbt.Keys.`package`).value\n  val classpath = (Compile / managedClasspath).value\n  val mainclass = (Compile / packageBin / mainClass).value.getOrElse(sys.error(\"Expected exactly one main class\"))\n  val jarTarget = s\"/app/${jarFile.getName}\"\n  // Make a colon separated classpath with the JAR file\n  val classpathString = classpath.files.map(\"/app/\" + _.getName)\n    .mkString(\":\") + \":\" + jarTarget\n  new Dockerfile {\n    // Base image\n    from(\"openjdk:8-jre\")\n    // Add all files on the classpath\n    add(classpath.files, \"/app/\")\n    // Add the JAR file\n    add(jarFile, jarTarget)\n    // On launch run Java with the classpath and the main class\n    entryPoint(\"java\", \"-cp\", classpathString, mainclass)\n  }\n}\n```\n\nExample with a Dockerfile in the filesystem.\n```scala\ndocker / dockerfile := NativeDockerfile(file(\"subdirectory\") / \"Dockerfile\")\n```\n\nHave a look at [DockerfileExamples](examples/DockerfileExamples.scala) for different ways of defining a Dockerfile.\n\n#### Missing Dockerfile instructions\n\nDockerfile instructions that are missing from the sbt-docker DSL can still be used by calling the `.customInstruction(instructionName, arguments)` method.\nExample:\n```scala\nnew Dockerfile {\n  customInstruction(\"FROM\", \"openjdk AS stage1\")\n  run(\"build\")\n\n  customInstruction(\"FROM\", \"openjdk AS stage2\")\n  customInstruction(\"COPY\", \"--from=stage1 /path/to/file /path/to/file\")\n  customInstruction(\"STOPSIGNAL\", \"SIGQUIT\")\n  \n  entryPoint(\"application\")\n}\n```\n\n### Building an image\n\nTo build an image use the `docker` task.\nSimply run `sbt docker` from your prompt or `docker` in the sbt console.\n\n### Pushing an image\n\nAn image that have already been built can be pushed with the `dockerPush` task.\nTo both build and push an image use the `dockerBuildAndPush` task.\n\nThe `docker / imageNames` key is used to determine which image names to push.\n\n### Custom image names\n\nYou 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]`.\n\nExample:\n```scala\ndocker / imageNames := Seq(\n  // Sets the latest tag\n  ImageName(s\"${organization.value}/${name.value}:latest\"),\n\n  // Sets a name with a tag that contains the project version\n  ImageName(\n    namespace = Some(organization.value),\n    repository = name.value,\n    tag = Some(\"v\" + version.value)\n  )\n)\n```\n\n### Build options\n\nUse the key `docker / buildOptions` to set build options.\n\n#### cross-platform\nThe `platforms` parameter enables the cross-platform build.\nWith valuing this parameter the docker image will build using `buildx` command and the host environment should already been set up for.\n\n⚠️ For using the cross builds you need QEMU binaries\n```shell\ndocker run --privileged --rm tonistiigi/binfmt --install all\n```\n\n#### Example:\n```scala\ndocker / buildOptions := BuildOptions(\n  cache = false,\n  removeIntermediateContainers = BuildOptions.Remove.Always,\n  pullBaseImage = BuildOptions.Pull.Always,\n  platforms = List(\"linux/arm64/v8\"),\n  additionalArguments = Seq(\"--add-host\", \"127.0.0.1:12345\", \"--compress\")\n)\n```\n\n### Build arguments\n\nUse the key `docker / dockerBuildArguments` to set build arguments.\n\nExample:\n```scala\ndocker / dockerBuildArguments := Map(\n  \"KEY\" -\u003e \"value\",\n  \"CREDENTIALS\" -\u003e sys.env(\"CREDENTIALS\")\n)\n\ndocker / dockerfile := {\n  new Dockerfile {\n    // ...\n    arg(\"KEY\")\n    arg(\"CREDENTIALS\")\n    env(\"KEY\" -\u003e \"$KEY\", \"CREDENTIALS\" -\u003e \"$CREDENTIALS\")\n    // ...\n  }\n}\n```\n\n### BuildKit support\n\nImages can be built with [BuildKit](https://docs.docker.com/develop/develop-images/build_enhancements/) by enabling it in the daemon configuration or by passing the environment variable `DOCKER_BUILDKIT=1` to sbt.\n\n[docker]: https://www.docker.com/\n[dockerfile]: https://docs.docker.com/engine/reference/builder/\n[dockerizing-scala-apps]: https://velvia.github.io/Docker-Scala-Sbt/\n[sbt]: http://www.scala-sbt.org/\n[sbt-assembly]: https://github.com/sbt/sbt-assembly\n[sbt-native-packager]: https://github.com/sbt/sbt-native-packager\n","funding_links":[],"categories":["Scala","Development with Docker","BUILD \u0026 RELEASE","Release","scala","Table of Contents","Sbt plugins"],"sub_categories":["API Client","Sbt plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcuslonnberg%2Fsbt-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcuslonnberg%2Fsbt-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcuslonnberg%2Fsbt-docker/lists"}