This is a simple Docker tutorial for creating your first NodeJs container, above is the vid and below you will find the steps followed.
Steps
- Pre-reqs
- Create an incredibly simple node app
- Create your first container
- Build and Run your new container
Create your simple node app
- npm init
- create the index.js
Create a dockerfile
- Include container with node preinstalled:
- FROM node
- Create default/working directory:
- WORKDIR /usr/src/app
- Copy package.json to workdir and install dependencies (not really needed for this app but you might need it😊):
- COPY package.json .
- RUN npm install
- Copy the rest of the app (just the index.js file in this case)
- COPY . .
- Add a command to run when this container is started
- CMD ["node", "index.js"]
Build & Run
- Build the container:
- docker build -t my-node-app .
- Run the container
- docker run my-node-app
Comentarios
Publicar un comentario