dev-resources.site
for different kinds of informations.
Building a Simple Cloud-Native App with Docker
Published at
12/1/2024
Categories
devops
cloudnative
microservices
node
Author
jajera
Author
6 person written this
jajera
open
Building a Simple Cloud-Native App with Docker
In this demo, we'll create a basic cloud-native application using Docker. This app will run in a container, and we’ll explore how Docker enables cloud-native principles such as portability and isolation.
Step 1: Create a Simple Node.js Microservice
- First, create a
server.js
file:
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello from Docker Cloud-Native App!');
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
- Install dependencies:
npm init -y
npm install express
Step 2: Dockerize the Application
- Create a Dockerfile to define the container:
# Use official Node.js image from Docker Hub
FROM node:20
# Set working directory inside the container
WORKDIR /app
# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install
# Copy the rest of the app's source code
COPY . .
# Expose the port the app will run on
EXPOSE 3000
# Command to run the app
CMD ["node", "server.js"]
Step 3: Build and Run the Docker Container
- Build the Docker image:
docker build -t cloud-native-app .
- Run the container:
docker run -p 3000:3000 cloud-native-app
Step 4: Access the Application
- Open your browser and visit
http://localhost:3000
. You should see:
Hello from Docker Cloud-Native App!
Conclusion
You've successfully built and run a simple cloud-native application using Docker. This app is now isolated in a container, and you can easily move or scale it across different environments without worrying about dependencies.
cloudnative Article's
30 articles in total
Exploring the CNCF Landscape: A Comprehensive Overview of Cloud Native Technologies
read article
Highlights from Our January 2025 Cloud Native KL Event: Open Policy Agent, DexIDP Single Sign-On, and More!
read article
Understand Kubernetes Troubleshooting Cheat Sheet Now
read article
Understanding Node Problem Detector in Kubernetes: Beyond Default Node Conditions
read article
Site Reliability Engineering (SRE)
read article
What is Cloud Native?
read article
Managing Sensitive Data in Kubernetes: A Comprehensive Guide to K8s Secrets
read article
How to Automate CI/CD Pipelines with GitHub Actions
read article
Frugal Architecture: Embracing Cost-Effective Cloud-Native Design
read article
Hidden Power of Go: Unveiling the Secrets of a Robust Language
read article
Do you run your database on Kubernetes?
read article
Implementing Automated Scaling with Horizontal Pod Autoscaling (HPA)
read article
10,000 Followers on Dev.to
read article
12 Factor App Principles Explained
read article
Unlocking Cloud-Native Security with Cilium and eBPF
read article
A Cost-Effective Guide to prepare and pass the KCNA
read article
Bare Metal Provisioning Consulting Services Experts
read article
Cloud Migration Best Practices
read article
The Power of AWS Services
read article
Generics in Go: Transforming Code Reusability
read article
Leveraging AWS Lambda for a Modern Nigerian Lifestyle: A Serverless Computing Solution
read article
Leveraging AWS EC2 for a Modern Nigerian Lifestyle: A Cloud Computing Solution
read article
Kubernetes CRDs: The Backbone of Kubernetes Extensibility
read article
Tackling CPU Throttling in Kubernetes for Better Application Performance
read article
Key Lessons and Mistakes from Setting Up EKS Clusters
read article
Building a Simple Cloud-Native App with Docker
currently reading
Optimizing Kubernetes for High Availability (HA)
read article
Deploying and Managing Microservices with Kubernetes
read article
Scaling Applications with Kubernetes: A Guide to Horizontal Pod Autoscaling (HPA)
read article
Leveraging Docker for Cloud-Native Application Development
read article
Featured ones: