Running a Scala Application using Docker
Last Updated :
24 Apr, 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
Running a Ruby Application using Docker
Pre-requisite:- Docker Docker is a containerization platform that allows you to package your applications and their dependencies into a lightweight and portable containers. Using Docker, you can easily deploy and run your applications on any platform that supports Docker, without having to worry abo
4 min read
How to Use Docker Images For Scaling Applications?
Docker image is a lightweight piece of software that includes everything that your application needs to run, it includes code, software packages, and libraries. Docker images are built using a Docker file which includes the instruction for creating the image. The Docker image is built on top of a ba
4 min read
How To Use Docker For IoT Applications?
Docker is a super tool that makes our lives much less complicated by providing us with standardization, productivity, performance, maintainability, and compatibility of our code. It lets us continuously and hastily install and test our code, and it is platform-impartial. Docker provides the ability
8 min read
Managing Dependencies in Dockerized Applications
Docker uses a daemon service with root privileges to run an application or a Dockerfile in an isolated environment. Dockerfile can have a lot of dependencies in it, and managing those is an important part in creating a docker image to be used by anyone in any environment. In this article, we will le
3 min read
Docker Compose for Node.js Applications
Docker Compose is a powerful tool that facilitates managing multi-container Docker applications. While developing Node.js applications, it usually gets to a point where you need to interact with services such as a database, message broker, or cache system. Manually handling these services can be qui
6 min read
How to Dockerize Angular Application
Dockerizing an Angular application involves packaging it into a Docker container, which can simplify deployment and ensure consistency across different environments. Docker is a containerization platform that allows you to package applications and their dependencies into lightweight, portable contai
5 min read
Deploying Scalable Applications with Azure
In modern software development, deploying a scalable application is an important task. With the increase in the number of users, the applications have to handle a large user database, for this, they require a robust infrastructure that is also scalable which will ensure seamless performance and reli
7 min read
How to Run GUI Based Applications inside Docker?
A Docker Container is an isolated application platform that contains everything needed to run an application built from one or more images. Docker is an Open Source project that provides an open platform to run any number of applications inside a container according to your requirements and you can
7 min read
How to Dockerize a Django Application?
Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers(namespace). To understand this perspective in a detailed way let's do a quick comparison between the virtual machines and containers:Imagine virtualization as a lock t
6 min read
Dockerize Spring Boot Application With PostgresSQL
In recent years, Docker has revolutionized the way in which we deploy and manage applications, offering a lightweight and productive solution for packaging software and its conditions into containers. For developers working with Spring Boot, a well known Java system for building undertaking grade ap
8 min read