We have a simple Nodejs app built using less than 10 lines.
We are going to containerise this app into a Docker Container.
- Simple Nodejs & Express App
- Official Node Image
- Get Started Docker
- Docker Desktop
- VSCode & Official Docker Extension
- Learn Docker in 7 Easy Steps - Full Beginner's Tutorial
- Clone this repo
gh repo clone cloudbrilliant/cuddly-chainsaw - Run
npm ito install express - Run & test the app locally
npm start - Local test url http://localhost:8080
Dockerfile is required in order to create image/container version of your app.
FROM node:14
WORKDIR /app
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install
COPY . .
ENV PORT=8080
EXPOSE 8080
CMD ["npm", "start"]Build an image from a Dockerfile
the -t flag tags our image. Think of this simply as a human-readable name for the final image. Since we named the image getting-started, we can refer to that image when we run a container.
The . at the end of the docker build command tells that Docker should look for the Dockerfile in the current directory.
docker build -t getting-started/demoapp:1.0 . Run the command below to start your new image / container
The -p command maps the container port to a local port, in our case this opens up https://localhost:3000
docker run -p 3000:8080 getting-started/demoapp:1.0