Running a Scala Application using Docker
Last Updated :
23 Jul, 2025
Docker has revolutionized the way applications are developed, deployed, and scaled. In this article, we will delve into Scala, a powerful programming language, and explore how to run a Scala application using Docker. Whether you are a beginner or an experienced developer, this step-by-step guide will help you understand the process easily.
Scala is widely used in industry, particularly in environments where the benefits of both object-oriented and functional programming are appreciated. It's commonly used in big data processing frameworks like Apache Spark and has a strong presence in the web development community.
Prerequisites
Before we begin, make sure you have the following prerequisites installed on the local system:
- Docker: Visit Docker's official website to download and install Docker on your local machine.
- Scala: If you don't have Scala installed, you can get it from the official Scala website OR you can refer GeeksForGeeks Article here.
Check your setup with the command, which should output:
scala --version
docker --version
Output


Create a Scala Application
Start by creating a simple Scala application. Open your favourite code editor I prefer VS Code and create a new file, for example, Hello.scala. Enter the following code:
Scala
// Scala program to print Hello World!
object Geeks {
// Main Method
def main(args: Array[String]): Unit = {
// prints Hello World
println("Hello Geeks!")
}
}
After completing the installation process, any IDE or text editor can be used to write Scala Codes and Run them on the IDE or the Command prompt with the use of command:
scalac file_name.Scala
scala class_name
Output
Scala application ouputCreate a Dockerfile
Create a new file named Dockerfile in the same directory as your Scala file. Add the following content to it:
FROM openjdk:8-jre-slim
This line sets the base image for the Docker image. We are using the official OpenJDK 8 runtime image.
WORKDIR /app
Sets the working directory within the container to /app.
COPY . /app:
Copies the contents of the current directory (where the Dockerfile is located) into the container at /app.
RUN apt-get update && \
apt-get install -y scala
The RUN instruction in a Dockerfile is used to execute commands during the image-building process
RUN scalac Geeks.scala
This command compiles the Scala code (Geeks.scala) using the scalac compiler. The compiled bytecode will be generated with the same name as the Scala file but with a .class extension.
CMD ["scala", "Geeks"]:
Specifies the command to run when the container starts. In this case, it runs the compiled Scala program using the scala command with the entry point being the Geeks object.
Overall Dockerfile :
# Use an official Scala runtime as a parent image
FROM openjdk:8-jre-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install Scala
RUN apt-get update && \
apt-get install -y scala
# Compile the Scala code
RUN scalac Hello.scala
# Run the Scala program
CMD ["scala", "Geeks"]
If you want to know more about Dockerfile creation then please visit GeeksForGeeks Article Here.
Building a Docker Image
Assuming you have the Dockerfile and your Scala code (Geeks.scala) in the same directory, you can build and run the Docker image
# Build the Docker image
docker build -t <image_name> <tag> <path_to_dockerfile_directory>
docker build -t docker-scala-img .
Output
-(1).png)
If you are getting error during creation of docker image then create .dockerignore file and add .metals/ to created file.
The Overall Root Directory Should Looks Like

To see the created Docker images use following command :
docker images
Output

Also you can see images using Docker Desktop application,

Run the Docker Container:
After building the image, run the Docker container with the following command:
docker run <image-name>
Output

Also you can see Running Container using Docker Desktop application,
.png)
You should see the output "Hello, Geeks!" indicating that your Scala application is running inside a Docker container.
Similar Reads
DevOps Tutorial DevOps is a combination of two words: "Development" and "Operations." Itâs a modern approach where software developers and software operations teams work together throughout the entire software life cycle.The goals of DevOps are:Faster and continuous software releases.Reduces manual errors through a
7 min read
Introduction
What is DevOps ?DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
10 min read
DevOps LifecycleThe DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
10 min read
The Evolution of DevOps - 3 Major Trends for FutureDevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
7 min read
Version Control
Continuous Integration (CI) & Continuous Deployment (CD)
Containerization
Orchestration
Infrastructure as Code (IaC)
Monitoring and Logging
Microsoft Teams vs Slack Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
4 min read
Security in DevOps