This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

Dockerized Microservices in springBoot 

  • Spring Boot
  • September 17, 2024

Share On :

Introduction

Microservices architecture has become standard for building scalable, flexible, and maintainable applications. In microservices, each service is designed to operate independently, which allows for isolated scaling, easier debugging, and independent deployments.However, managing and deploying microservices can be complex and time-consuming. This is where Docker comes in.

Docker simplifies microservice architecture by providing lightweight, isolated containers to run each service. In this blog post, we will explore how to dockerize a microservices architecture using a dummy project for an online learning platform, which includes services like eureka-server (discovery service), api-gateway, user-service, course-service, and admin-service.

Why Docker

Docker is an open platform that can be used to deploy applications in secure containers. Docker containers are lightweight, simple to configure and work consistently in IT environments. Most Bitnami applications are available as Docker containers and offer all the usual Bitnami benefits: security, optimization, consistency and frequent updates.

Docker is a popular platform used for developing, shipping, and running applications. It enables developers to package their applications and their dependencies into standardized units called containers. These containers can then be easily moved between environments, such as development, testing, and production, ensuring consistency across different systems.

combining Microservices with Docker simplifies the deployment of applications, enhancing flexibility and efficiency in the software development lifecycle. This approach not only facilitates easier management but also ensures consistency and reliability across various deployment environments.

Prerequisites
  • Docker : Docker is essential for containerizing microservices. 
  • Docker Compose : Docker Compose simplifies multi-container Docker applications.
  • Java 17 : Our microservices are built using Spring Boot, which runs on Java 17.
  • Maven : Maven is required for building Spring Boot projects. 
  • Spring Boot Development Environment (here IntelliJ IDEA).
Project Structure
				
					onlineLearningDemo/
├── admin-service/
├── api-gateway/
├── course-service/
├── discovery-service/
├── user-service/
├── docker-compose.yml
				
			

Each microservice has its own Spring Boot application and is containerized using Docker. The docker-compose.yml file helps orchestrate all the containers.

Setting Up  Spring Boot Application 

Create  Microservices that you need for your application. I’m going to implement a  dummy project for an online learning platform, which includes services like eureka-server (discovery service), api-gateway, user-service, course-service, and admin-service.

Step 1 : Writing the Dockerfile for Each Service

Each service needs its own Dockerfile to build the respective Docker image. Below is an example Dockerfile for the course-service:

				
					# Use a base image that has Java installed
FROM openjdk:17-jdk-alpine

# Set the working directory inside the container
WORKDIR /app

# Copy the Spring Boot jar to the container
COPY target/course-service-1.0-SNAPSHOT.jar course-service.jar

# Expose the port on which the service will run
EXPOSE 8081

# Define the command to run the jar
ENTRYPOINT ["java", "-jar", "course-service.jar"]
				
			

Navigate to the project directory in the command prompt, and execute the following command to build the Docker image:

				
					docker build -t course-service .
				
			

Repeat similar steps for the admin-service, api-gateway-service, course-service, and discovery-service.

Let’s break down this Dockerfile

  • FROM openjdk : 17-jdk-alpine

This line specifies the base image for your Docker image. In this case, you’re using the openjdk:17-jdk-alpine image, which is an official Docker image that includes the OpenJDK 17 runtime on an Alpine Linux base. Alpine Linux is known for its small size, which makes the image more lightweight.

  • WORKDIR /app

This line sets the working directory inside the Docker container to /app. Any subsequent commands (like COPY or RUN) will be executed in this directory. If the /app directory does not exist, it will be created. This is where your application files will be placed and run.

  • COPY target/course-service-1.0-SNAPSHOT.jar course-service.jar

This line copies the course-service-1.0-SNAPSHOT.jar file from your local target directory (where it was built) into the /app directory inside the Docker container. The file is renamed to course-service.jar in the container. This is the executable JAR file of your Spring Boot application.

  • EXPOSE 8081

This line informs Docker that the container will listen on port 8081. This is useful for documenting which port the application is expected to run on and is used when configuring Docker networking to allow connections to this port.

  • ENTRYPOINT [“java”, “-jar”, “course-service.jar”]

This line defines the command that will be executed when the container starts. In this case, it runs the java -jar course-service.jar command, which starts your Spring Boot application. The ENTRYPOINT instruction sets the command and its arguments that will be used to run the container.

Step 2 : Defining the Docker Compose File

We need to define how all the services will interact within Docker. Below is the docker-compose.yml file, which contains all the services and the network configuration:

				
					services:
  eureka-server:
    build:
      context: ./discovery-service
      dockerfile: Dockerfile
    container_name: discovery-server
    ports:
      - "8761:8761"
    networks:
      - microservices-network
  user-service:
    build:
      context: ./user-service
      dockerfile: Dockerfile
    container_name: user-service
    ports:
      - "8083:8083"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  course-service:
    build:
      context: ./course-service
      dockerfile: Dockerfile
    container_name: course-service
    ports:
      - "8081:8081"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  admin-service:
    build:
      context: ./admin-service
      dockerfile: Dockerfile
    container_name: admin-service
    ports:
      - "8082:8082"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  api-gateway:
    build:
      context: ./api-gateway
      dockerfile: Dockerfile
    container_name: api-gateway
    ports:
      - "8080:8080"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  mysql:
    image: mysql:8.0
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      # Create multiple schemas (databases) for each service
      MYSQL_DATABASE: default_db
      MYSQL_USER: user
      MYSQL_PASSWORD: userpassword
    ports:
      - "3306:3306"
    volumes:
      - db-data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - microservices-network
    command: >
      --default-authentication-plugin=mysql_native_password
      --init-file=/docker-entrypoint-initdb.d/init.sql
networks:
  microservices-network:
    driver: bridge
volumes:
  db-data:

				
			

Step 3 : Building and Running the Docker Containers

Once all the Dockerfile files are created, and the docker-compose.yml file is set up, you can build and start all the services using Docker Compose.

Run the following command to build and start the containers:

				
					docker-compose up --build
				
			

This command will:

  • Build Docker images for all services using their respective Dockerfile.
  • Create containers for each service.
  • Start all containers and expose the necessary ports as defined in the docker-compose.yml.

Step 4 : Verifying the Setup

Once the services are up and running, you can verify the setup by visiting the following URLs:

  • Eureka Server : Open http://localhost:8761 in your browser to check if all services are registered.
  • API Gateway : You can interact with your APIs via http://localhost:8080.
Eureka Server Page (1)
Conclusion

Dockerizing microservices offers a clean and scalable way to manage independent services. Using Docker and Docker Compose, we can containerize and orchestrate a microservices-based architecture efficiently. In this blog, we walked through the process of Dockerizing an online learning platform with multiple services, demonstrating how to create Docker images, manage containers, and ensure smooth communication between services.

By leveraging Docker, we make our applications more scalable, portable, and easier to deploy across different environments.

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.

Stay informed about our Spring Boot services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

March 28, 2024
Spring Boot With Docker
Dockerize Spring Boot Application
August 30, 2024
Building Resilient Spring Boot Microservices with Circuit Breaker Patterns using Resilience4j
Building Resilient Spring Boot Microservices with Circuit Breaker Patterns using Resilience4j
Loading...

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram