Pre-requisites:
This section of the workshop assumes you have docker installed. Follow the instructions at https://docs.docker.com/get-docker/.
Create a new directory “apprunner-example”, and in this directly, create the following files:
index.js
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('AppRunner 101!');
});
app.listen(port, () => {
console.log(`NodeJS Application is listening at http://localhost:${port}`);
});
package.json
{
"name": "apprunner101",
"version": "1.0.1",
"description": "",
"main": "index.js",
"dependencies": {
"express": "^4.18.1"
},
"devDependencies": {},
"author": "nnthanh101@gmail.com",
"license": "MIT"
}
Dockerfile
FROM node:16
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
EXPOSE 3000
CMD [ "node", "index.js" ]
You should now have the following files in your directory:
nnthanh@:~/apprunner$ ls
Dockerfile index.js package.json