DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Dockerizing Your Scala App

Dockerizing Your Scala App

Here's a step-by-step guide that details how to containerize your Scala apps with Docker, including how to set up your Dockerfile.

Emmanouil Gkatziouras user avatar by
Emmanouil Gkatziouras
CORE ·
May. 15, 18 · Tutorial
Like (4)
Save
Tweet
Share
17.05K Views

Join the DZone community and get the full member experience.

Join For Free

Dockerizing a Scala application is pretty easy.

The first concern is creating a fat JAR. Now, we all come from different backgrounds, including Maven/Gradle and different plugins that handle this issue. If you use sbt, the way to go is to use the sbt-assembly plugin.

To use it, we should add it to our project/plugins.sbt file. If the file does not exist, create it.

logLevel := Level.Warn

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")


So by executing...

sbt clean assembly


...we will end up with a fat JAR located at the target/scala-**/**.jar path.

Now the easy part is putting our application inside Docker. Thus, a Dockerfile is needed.

We will use OpenJDK Alpine as a base image.

FROM openjdk:8-jre-alpine

ADD target/scala-**/your-fat-jar app.jar

ENTRYPOINT ["java","-jar","/app.jar"]


The above approach works all right and gives you the control needed to customize your build process. For a more bootstrapped experience, you can use the sbt native packager.

All you need to do is to add the plugin to the project/plugins.sbt file.

logLevel := Level.Warn

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4")


Then we specify the main class of our application and enable the Java and Docker plugins from the native packager at the build.sbt file.

mainClass in Compile := Some("your.package.MainClass")

enablePlugins(JavaAppPackaging)
enablePlugins(DockerPlugin)


The next step is to issue the sbt command.

sbt docker:publishLocal


This command will build your application, include the binaries needed to the JAR, containerize your application, and publish it to your local Maven repo.

Scala (programming language) app application Docker (software) JAR (file format) Command (computing) Build (game engine) OpenJDK

Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • RabbitMQ vs. Memphis.dev
  • Three SQL Keywords in QuestDB for Finding Missing Data
  • Using QuestDB to Collect Infrastructure Metrics
  • A Beginner's Guide to Back-End Development

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: