lunes, 16 de septiembre de 2024

Docker file example with a node app

Create a directory with Dockerfile

mkdir NodeApp

cd NodeApp/

mkdir src

touch package.json

touch src/server.js

touch Dockerfile

vim package.json

{

    

    "name": "my-app",

    "version": "1.0",

    "dependencies": {

        "express": "4.18.2"

    }

    

}


vim src/server.js

const express = require('express');

const app = express();


app.get('/', (req,res)=>{

    res.send("Welcome to my awesome app!");

});


app.listen(3000, function () {

    console.log("app listening on port 3000");

});


vim Dockerfile

FROM node:19-alpine

COPY package.json /app/

COPY src /app/

WORKDIR /app

RUN npm install

CMD ["node", "server.js"]


docker build -t node-app:1.0 .

docker image list

docker run -d -p 3000:3000 node-app:1.0

docker ps

No hay comentarios:

Publicar un comentario