Dockerize the NodeJs (local)
??
In this post, let's explore how to dockerize a Node.js application on a local machine.
Contents
Install docker:
Initiate Simple NodeJs App
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Dockerize the NodeJs app?
FROM node:19-alpine
COPY package.json /app/
COPY app.js /app/
WORKDIR /app
RUN npm install
CMD ["node","app.js"]
Build Image
领英推荐
docker build -t docker-app.
Run the Image
docker run -d -p 3000:9000 docker-app:latest
docker ps
Output
To delete the container,
docker stop <Container ID>
docker rm <Container ID>
Thanks
Lead Test engineer / Game Design (iGaming)
7 个月Very helpful!