Skip to content

codewithmuh/dockerize-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Node.js Server with Docker

1i (54)

Youtube Video Link: https://youtu.be/7FGj4EwOX2E

This project sets up a basic Node.js server that serves an HTML file. The server is then containerized using Docker.

  • index.html: The HTML file to be served.
  • server.js: The Node.js server code.
  • Dockerfile: Instructions to build the Docker image.
  • .dockerignore: Specifies which files and directories to ignore when building the Docker image.
  • package.json: Contains the project metadata and dependencies.

Prerequisites

  • Node.js (if you need to test the server locally without Docker)
  • Docker

Setup and Run

Running the Server Locally

  1. Clone the repository:

    git clone https://github.com/yourusername/my-node-server.git
    cd my-node-server
  2. Install dependencies (if any):

    npm install
  3. Start the server:

    npm start
  4. Open your browser and navigate to http://localhost:3000.

Running the Server with Docker

  1. Clone the repository (if you haven't already):

    https://github.com/codewithmuh/dockerize-nodejs.git
    cd my-node-server

Using node:20 docker image

  1. Build the Docker image:

    docker build -t my-node-server .
  2. Run the Docker container:

    docker run -it --rm -p 3000:3000 my-node-server
  3. Open your browser and navigate to http://localhost:3000.

Using chainguard cgr.dev/chainguard/node:latest docker image

  1. Build the Docker image:

    docker build -f  Dockerfile-distroless -t my-node-cg .
  2. Run the Docker container:

    docker run -it --rm -p 3000:3000 my-node-cg
  3. Open your browser and navigate to http://localhost:3000.

About

Dockerize Nodejs app using chainguard

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published