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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How To Dockerize Mean Stack App
  • 5 Simple Tips to Keep Dockerized Apps Secure
  • Implementing and Deploying the Domain Project With MuleSoft
  • How To Use the Node Docker Official Image

Trending

  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • Simplify Authorization in Ruby on Rails With the Power of Pundit Gem
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • Scalability 101: How to Build, Measure, and Improve It
  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.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
May. 15, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
18.7K 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.

Related

  • How To Dockerize Mean Stack App
  • 5 Simple Tips to Keep Dockerized Apps Secure
  • Implementing and Deploying the Domain Project With MuleSoft
  • How To Use the Node Docker Official Image

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: