https://github.com/yadavvishal/dockerfiles
This project runs a simple Node.js application inside a Docker container.
https://github.com/yadavvishal/dockerfiles
docker-image dockerfile
Last synced: 10 months ago
JSON representation
This project runs a simple Node.js application inside a Docker container.
- Host: GitHub
- URL: https://github.com/yadavvishal/dockerfiles
- Owner: yadavvishal
- Created: 2025-02-07T11:00:09.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-02-13T22:58:32.000Z (12 months ago)
- Last Synced: 2025-04-12T00:49:10.686Z (10 months ago)
- Topics: docker-image, dockerfile
- Language: JavaScript
- Homepage:
- Size: 696 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README (1).md
Awesome Lists containing this project
README
# Node.js Application in a Docker Container
This project runs a simple Node.js application inside a Docker container.
## Prerequisites
- Docker installed on your system
- Node.js (for local testing, optional)
## Project Structure
```
.
├── Dockerfile
├── main.js
├── package.json
├── package-lock.json
```
## Setup and Usage
### 1. Build the Docker Image
Run the following command to build the Docker image:
```sh
docker build -t my-node-app .
```
### 2. Run the Container
To run the application inside a container, use:
```sh
docker run -p 8000:8000 my-node-app
```
This binds the container's port `8000` to the host machine's port `8000`.
### 3. Access the Application
Once the container is running, open your browser and visit:
```
http://localhost:8000
```
You should see the following response:
```json
{
"message": "Hey, I am nodejs in container"
}
```
## Dockerfile Explanation
- Uses `ubuntu` as the base image.
- Updates system packages and installs `curl`.
- Sets up Node.js version 18.
- Copies `package.json`, `package-lock.json`, and `main.js` into the container.
- Installs dependencies using `npm install`.
- Runs `main.js` as the application entry point.
## Stopping the Container
To stop the running container, press `CTRL + C` in the terminal or find and stop the container using:
```sh
docker ps
```
Find the container ID and stop it using:
```sh
docker stop
```
## Cleanup
To remove the container and image:
```sh
docker rm
docker rmi my-node-app
```
## License
This project is open-source and available for modification and distribution.