Packaging Scala applications as Docker images
Scala CLI can create an executable application and package it into a Docker image.
For example, here's a simple piece of code that will be executed in a Docker container:
HelloDocker.scala
object HelloDocker extends App {
println("Hello from Docker")
}
Passing --docker
to the package
sub-command generates a Docker image. When creating a Docker image, the --docker-image-repository
parameter is mandatory.
The following command generates a hello-docker
image with the latest
tag:
scala-cli package --docker HelloDocker.scala --docker-image-repository hello-docker
docker run hello-docker
# Hello from Docker
You can also package your app in the Scala.js or Scala Native environments. For example, this command creates a Scala.js Docker image:
scala-cli package --js --docker HelloDocker.scala --docker-image-repository hello-docker
This command creates a Scala Native Docker image:
scala-cli package --native --docker HelloDocker.scala --docker-image-repository hello-docker
note
Packaging a Scala Native application to a Docker image is supported only on Linux.