Sign inSign up

cabohorquez/hello-worldjs

By cabohorquez

•Updated almost 2 years ago

JS hello world docker

Image
Languages & frameworks
0

283

cabohorquez/hello-worldjs repository overview

⁠Node.js Hello World Docker Image

This repository contains a simple "Hello World" application in Node.js, set up to run on Docker.

⁠Dockerfile

The Dockerfile uses the official Node.js 16 image, copies the project files, installs dependencies, and exposes port 4000.

# Use the latest Node.js image
FROM node:16

# Copy the project files into the container
COPY . /src

# Set the working directory inside the container
WORKDIR /src

# Install the dependencies
RUN npm install

# Expose port 4000
EXPOSE 4000

# Command to run the application
CMD ["node", "server.js"]
⁠Node.js Code - server.js
var http = require('http');
var port = 4000;

var server = http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World
');
});

server.listen(port);

console.log('Server running at http://localhost:' + port);

⁠How to Use the Docker Image

  1. Pull the Image from Docker Hub

    docker pull cabohorquez/hello-worldjs
    
  2. Run the Docker Container

    docker run -p 4000:4000 cabohorquez/hello-worldjs
    
  3. Access the Application Open your browser and navigate to http://localhost:4000. You should see the message Hello World displayed on the screen.

⁠Additional Notes

  • Ensure Docker is installed and running.
  • The application runs on port 4000. Adjust port mapping if necessary.

⁠Files Ignored (.dockerignore)

The following files are ignored in the build:

  • node_modules/
  • npm-debug.log

Tag summary

Content type

Image

Digest

sha256:914f29b35…

Size

332.8 MB

Last updated

almost 2 years ago

docker pull cabohorquez/hello-worldjs