Question

ASP.NET Core and SpringBoot applications side by side in a droplet

Is it possible to host two different applications like ASP.NET Core (C#) and SpringBoot (Java) side by side in a droplet?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi there,

Yes, this is totally doable. What I would personally do here would be to use Docker. That way your apps will be isolated and you will not have to install all of the dependencies on your server directly but you would only run your containers.

You can start with the Docker 1-Click image from the Marketplace here:

https://marketplace.digitalocean.com/apps/docker

Then if your apps are not Dockerized yet, you could do that by following these steps here:

For your ASP.NET Core app:

  1. Publish your ASP.NET Core application:

    dotnet publish -c Release
    
  2. Create a Dockerfile in the root of your ASP.NET Core project:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY published/ ./
ENTRYPOINT ["dotnet", "your_app.dll"]

For your your SpringBoot application, if it runs as a JAR, create a Dockerfile in the root of your SpringBoot project:

FROM openjdk:11
MAINTAINER baeldung.com
COPY target/docker-java-jar-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Then you can build your Docker images and start your containers on your Droplet.

Navigate to each project’s directory and build the Docker images:

# For ASP.NET Core
docker build -t aspnetcoreapp .

# For SpringBoot
docker build -t springbootapp .

Now, you can run each application in its own Docker container:

docker run -d -p 8080:80 aspnetcoreapp
docker run -d -p 9090:8080 springbootapp

Your ASP.NET Core application should be accessible at http://your_droplet_ip:8080 and your SpringBoot application at http://your_droplet_ip:9090.

Next, you can add Nginx to work as a reverse proxy so you don’t have to specify your ports.

A few things that you could consider are:

  • Docker Compose: If you plan to run multiple containers frequently, consider using Docker Compose. It allows you to define and manage multi-container Docker applications.

  • Data Persistence: If your applications need to store data, consider volume mapping to ensure data persistence outside of the container.

  • Manage Resources: Be mindful of your Droplet’s resources (CPU, memory). Running multiple applications, especially on a small droplet, can consume resources quickly.

The main benefit again is that each application runs in its isolated environment, ensuring that dependencies and configurations don’t conflict.

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel