JS hello world docker
283
This repository contains a simple "Hello World" application in Node.js, set up to run on Docker.
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"]
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);
Pull the Image from Docker Hub
docker pull cabohorquez/hello-worldjs
Run the Docker Container
docker run -p 4000:4000 cabohorquez/hello-worldjs
Access the Application
Open your browser and navigate to http://localhost:4000. You should see the message Hello World displayed on the screen.
The following files are ignored in the build:
node_modules/npm-debug.logContent type
Image
Digest
sha256:914f29b35…
Size
332.8 MB
Last updated
almost 2 years ago
docker pull cabohorquez/hello-worldjs