How to create a docker image with a node js express website, push it to azure container registration(ACR), create a linux web app for containers and configure it to run the docker image stored in the ACR.

 

I just created a very simple node.js express web app and wanted to deploy it to azure.

 

Install Node.js and Docker for Windows.

Create a Folder, navigate to it from a commandline and run npm Init.

Then run npm install express –save to install the java script express framework

Then create a app.js file and copy the following:

const express = require(‘express’);

const app = express();

app.get(‘/’, (req, res) => res.send(‘<h1>Hello World 123!</h1>’))

app.listen(3000, () => console.log(‘Example app listening on port 3000!’))

 

Its a good idea to try and run it on your local machine first: 

node app.js

open a browser and navigate to localhost:3000.

you should get a Hello World 123! webresponse. 

 

Now create a DOCKERFILE (without file-extension) in the same directory and copy paste the following and save it:

 

FROM node:6

WORKDIR /app

COPY package.json /app

RUN npm install

COPY . /app

CMD node app.js

EXPOSE 3000

 

Next open a command line navigate to your folder and build your image:

docker build –t helloworld .

This will create a docker image from the node:6 base image (that comes from dockerhub.com) and add your web app to the image

you can run the docker image as a local container using:

docker run 3000:3000 helloworld

next step: go to azure portal and create a “Azure Container Registry”. just search it and fill out the form.

After deployment go to access keys in the settings menu of your Azure Container Registry and activate “administration user”.

 

Now you can connect your docker commandline session with this azure container registry (instead of dockerhub) by running:

docker login lukastimages.azurecr.io

Enter user and password from the Azure Portal to authenticate yourself. Sometimes i had issues connecting (i had the impression that restarting my local docker service or restarting my entire notebook helped.)

When the login was successful you can use the following two commands to push your helloworld image to your azure container registry:

 

docker tag helloworld lukastimages.azurecr.io/helloworld

docker push lukastimages.azurecr.io/helloworld

Depending on your uploadspeed it will take some time.

When finished you can create a new Azure Website. In the Azure Portal search “Web app for containers”

You will find “Web-App under Linux”.

Click create and fill the form. There will be a Setting to configure a container image

image 

Create the Web-App and navigate to your website.

image

Thats it!

 

You can later change the container image of your Linux Web App: (and only in the linux web app! the container setting is not available in a windows web app!)

image

 

Now the cool thing is you can scale your website by running additional containers:

image

Add a Comment

Your email address will not be published. Required fields are marked *