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
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
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How To Dockerize Mean Stack App
  • 5 Simple Tips to Keep Dockerized Apps Secure
  • Dockerizing With a Custom JRE
  • Implementing and Deploying the Domain Project With MuleSoft

Trending

  • GenAI-Infused ChatGPT: A Guide To Effective Prompt Engineering
  • The Convergence of Testing and Observability
  • Spring WebFlux Retries
  • Microservices With Apache Camel and Quarkus (Part 5)
  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.80K 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
  • Dockerizing With a Custom JRE
  • Implementing and Deploying the Domain Project With MuleSoft

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

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

Let's be friends: