Sample code for using Node with Docker and Azure
Using Github:
-
Login to azure portal and create a new Web App
-
Open Settings of the web app and click "Continus Deployment"
-
Select the source as "Github"
-
Setup Authorization and Select the Project / Branch
Using Local Git Repository:
-
Login to azure portal and create a new Web App
-
Open Settings of the web app and click "Continus Deployment"
-
Select the source as "Local Git Repository"
-
Setup Deployment credentials
-
Verify the git repository url from Properties
-
Setup repository in local folder, where you have the code:
- git init
- git add .
- git commit -m "comments"
- git remote add azure [url of the local git repository which should be displayed in web app properties]
- git push azure master
-
Push more changes after changes
- git add .
- git commit -m "comments"
- git push azure master
(Note: Install Docker Toolbox and run the following commands in docker terminal)
-
Go to the directory containing the code.
-
Build a new the docker image (make sure to add the "." at the end)
- docker build -t jomit/idealistapp .
-
List all existing docker images and make sure the new image is in the list
- docker images
-
Run a docker image (-p is to map a local machine port to docker vm, -d is to run the image in background)
- docker run -d -p 5000:8080 --name="idealistapp-1" jomit/idealistapp
-
List all running images and make sure "idealistapp-1" is in the list
- docker ps
-
Check the IP of the VM running the docker host
- docker-machine ip default
-
Open the app in browser using the docker host ip from above
http://:5000/
- docker ps -a (see all stopped containers)
- docker stop $(docker ps -a -q) (Stop all running images)
- docker rm $(docker ps -a -q) (Remove all stopped images)
- winpty docker exec -it <container-id> bash (Go inside the container)
- docker logs <container-id> (see server logs of the vm)