Cloud computing and docker make web application deployment easy

1. Create a simple Node.js Express web application

const express = require("express")
const app = express()
const index = function (req, res) {
const date = new Date()
res.send(date.toISOString())
}
app.get("/", index)
const port = 3000
app.listen(port, () => console.log(`app listening at ${port}`))
FROM node:alpineWORKDIR /usr/src/appCOPY . /usr/src/appRUN npm installEXPOSE 3000CMD ["node", "index.js"]
Files in the folder
Files in the folder
docker build -t sample-web .

2. Push the image to GCP(Google Cloud Platform)

Make sure you have installed the Google Cloud SDK already. Run the following commands to push the docker image we just built to GCP Container Registry, so that the GCP can use the image to make deployment to GCE(Compute Engines). GCP can NOT use docker hub images to make deployments.

// make sure we login first
gcloud auth login
// make sure Google Cloud SDK can access the local docker images
gcloud auth configure-docker
// make tag to the docker images we just built
docker tag sample-web [HOSTNAME]/[GCP PROJECT ID]/[IMAGE]
// push the tagged image to google Container Registry
docker push [HOSTNAME]/[GCP PROJECT ID]/[IMAGE]

3. Deployment in GCP using “Instance Group” and “Load Balancer”

First, we create a instance template, go to “Compute Engine” -> “Instance templates” -> Click “create an instance template”.

click the Container checkbox

4. Now check it out!

We can now go to the HTTPS web address we configured for our web application. We shall see something like:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store