DEV Community

John  Ajera
John Ajera

Posted on

Building a Simple Cloud-Native App with Docker

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}`);
  });
Enter fullscreen mode Exit fullscreen mode
  • Install dependencies:
  npm init -y
  npm install express
Enter fullscreen mode Exit fullscreen mode

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"]
Enter fullscreen mode Exit fullscreen mode

Step 3: Build and Run the Docker Container

  • Build the Docker image:
  docker build -t cloud-native-app .
Enter fullscreen mode Exit fullscreen mode
  • Run the container:
  docker run -p 3000:3000 cloud-native-app
Enter fullscreen mode Exit fullscreen mode

Step 4: Access the Application

  • Open your browser and visit http://localhost:3000. You should see:
  Hello from Docker Cloud-Native App!
Enter fullscreen mode Exit fullscreen mode

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.

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
πŸŽ₯ Audio/video file upload with real-time preview
πŸ—£οΈ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
πŸ“€ Export interview's subtitles in VTT format

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay