Skip to content

Instantly share code, notes, and snippets.

@NileshGule
Last active February 22, 2018 22:29
Show Gist options
  • Save NileshGule/70ece2b159c2b71c4aeb24d724e4aec6 to your computer and use it in GitHub Desktop.
Save NileshGule/70ece2b159c2b71c4aeb24d724e4aec6 to your computer and use it in GitHub Desktop.

Hackathon 23 Feb 2018

Generate SSH key pair

ssh-keygen –t rsa

Provision Swm clusteer using Azure Resource template

Login to Azure account (not required in case of cloud shell)

az login

Set subscription ID (not required in case of cloud shell)

az account set --subscription "Visual Studio Enterprise"

az account set --subscription "Azure Pass"

Create resource group

az group create \
--name swarmresourcegroup \
--location "Southeast Asia"

Create deployment using local template file and parameters

time az group deployment create \
    --name "coredemo" \
    --resource-group "swarmresourcegroup" \
    --template-file azuredeploy.json \
    --parameters parameters.json

Build Docker images

Build single image

docker build -t coremvc .

Run the container (detached mode)

docker run -d -p 80:80 coremvc

Run the container (interactive mode)

docker run -it -p 80:80 coremvc

Run the container on a different host port

docker run -it -p 8080:80 coremvc

Build multi-container images locally using Docker Compose

docker-compose --file docker-compose-build.yml build

Run multi-containers locally

docker-compose --file docker-compose-build.yml up

Visualize Docker Swarm using Portainer

Open SSH tunnel to Swarm endpoint in SE Asia

ssh -fNL 2375:localhost:2375 -p 2200 [email protected]

Set DOCKER_HOST environment variable

export DOCKER_HOST=:2375

change availability of Swarm Master node

docker node update --availability=active swarmm-master-coredemo-0

Create Portainer Service

docker service create \
   --name portainer \
   --publish 9000:9000 \
   --constraint 'node.role == manager' \
   --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
   portainer/portainer \
   -H unix:///var/run/docker.sock

Visualize Swarm Resources

http://swarmagent.southeastasia.cloudapp.azure.com:9000/

Reset availability of Swarm Master node to Pause

docker node update --availability=pause swarmm-master-coredemo-0

Access MVC app & WebAPI using agent node

http://swarmagent.southeastasia.cloudapp.azure.com

http://swarmagent.southeastasia.cloudapp.azure.com:8080/api/keyvalue

Delete resources at the end

az group delete --name swarmresourcegroup --yes--no-wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment