Skip to content

Instantly share code, notes, and snippets.

@johnkors
Last active August 4, 2017 12:30
Show Gist options
  • Save johnkors/05eb0ea7dd90ce9919a672b1768eb090 to your computer and use it in GitHub Desktop.
Save johnkors/05eb0ea7dd90ce9919a672b1768eb090 to your computer and use it in GitHub Desktop.
Experiences using azure container instances

A small journey into azure container instances

λ az account list-locations | grep europe
    "id": "/subscriptions/be95d17f-ed23-4a74-b61f-56d51845f744/locations/northeurope",
    "name": "northeurope",
    "id": "/subscriptions/be95d17f-ed23-4a74-b61f-56d51845f744/locations/westeurope",
    "name": "westeurope",
λ az group create --name feilasresources --location northeurope
{
  "id": "/subscriptions/be95d17f-ed23-4a74-b61f-56d51845f744/resourceGroups/feilasresources",
  "location": "northeurope",
  "managedBy": null,
  "name": "feilasresources",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null
}

Make sure you have docker for windows running + setup using linux containers.

Create docker image (first time only)

docker build -t feilasnodeimage .

Create a tag:

λ docker tag feilasnodeimage johnkors/feilas:v1.0

Push tag:

λ docker push johnkors/feilas:v1.0
The push refers to a repository [docker.io/johnkors/feilas]
320b6d4ef665: Pushed
557f6b9b8354: Pushed
a33e0e2727b3: Pushed
d8fbd47558a8: Pushed
44ab46125c35: Pushed
5bef08742407: Pushed
v1.0: digest: sha256:229f5747d1f040ccf94d357017193c4de6e63a6f5cf950aa4fd5c9f0163f04ae size: 1574

Create container

λ az container create --name feilasweb --image johnkors/feilas --resource-group feilasresources --ip-address public 

Try to create a container, and fail:

λ az container create --name feilascontainer --image johnkors/feilas --resource-group feilasresources --ip-address public
The provided location 'northeurope' is not available for resource type 'Microsoft.ContainerInstance/containerGroups'. List of availa
ble regions for the resource type is 'westus,eastus,westeurope'.

Delete the old..

λ az group delete --name feilasresources
Are you sure you want to perform this operation? (y/n): y
 | Finished ..

Create a new resource group, this in the west of eu

λ az group create --name feilasresourceswesteu --location westeurope
{
  "id": "/subscriptions/be95d17f-ed23-4a74-b61f-56d51845f744/resourceGroups/feilasresourceswesteu",
  "location": "westeurope",
  "managedBy": null,
  "name": "feilasresourceswesteu",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null
}

Now try to create the container

λ az container create --name feilascontainer --image johnkors/feilas --resource-group  feilasresourceswesteu --ip-address public
{
  "containers": [
    {
      "command": null,
      "environmentVariables": [],
      "image": "johnkors/feilas",
      "instanceView": null,
      "name": "feilascontainer",
      "ports": [
        {
          "port": 80
        }
      ],
      "resources": {
        "limits": null,
        "requests": {
          "cpu": 1.0,
          "memoryInGb": 1.5
        }
      },
      "volumeMounts": null
    }
  ],
  "id": "/subscriptions/be95d17f-ed23-4a74-b61f-56d51845f744/resourceGroups/feilasresourceswesteu/providers/Microsoft.ContainerInsta
nce/containerGroups/feilascontainer",
  "imageRegistryCredentials": null,
  "ipAddress": {
    "ip": "104.47.159.55",
    "ports": [
      {
        "port": 80,
        "protocol": "TCP"
      }
    ]
  },
  "location": "westeurope",
  "name": "feilascontainer",
  "osType": "Linux",
  "provisioningState": "Creating",
  "resourceGroup": "feilasresourceswesteu",
  "restartPolicy": null,
  "state": null,
  "tags": null,
  "type": "Microsoft.ContainerInstance/containerGroups",
  "volumes": null
}

Poll for status until state shows Succeeded

λ az container show --name feilascontainer --resource-group feilasresourceswesteu
{
  ...
  "provisioningState": "Creating",
  "resourceGroup": "feilasresourceswesteu",
  ...
  "state": "Pending",
  ...
}

When completed, the status should be Succeeded.

It never did, but there was an error message about not finding my docker image. So trying to create a new one fetching via tags insted:

Delete the unused container. FAIL. I already deleted the resource group, and now cannot clean up the container. Must be a bug.

λ az container delete --name feilascontainer --resource-group feilasresources
Are you sure you want to perform this operation? (y/n): y
Resource group 'feilasresources' could not be found.
λ az container create --name feilascontainer2 --image johnkors/feilas:v1.0 --resource-group  feilasresourceswesteu --ip-address public
ic

Poll again

λ az container show --name feilascontainer2 --resource-group feilasresourceswesteu
{
  ...
  "provisioningState": "Succeeded",
  ...
  "state": "Running",
  ...
}

The address from show is:

  "ipAddress": {
    "ip": "104.47.159.62",
    "ports": [
      {
        "port": 80,
        "protocol": "TCP"
      }
    ]
  }

But nothing is showing up, so checking logs:

az container logs --name feilascontainer2 --resource-group feilasresourceswesteu

Empty.

Giving up.

.. Realising I'm listening to port 3000 in the app, creating a new container instance:

λ az container create --name feilascontainer3 --image johnkors/feilas:v1.0 --resource-group  feilasresourceswesteu --ip-address public --port 3000

That did not worker either, so changing my app to use port 80 instead and pushing a new docker image:

First a cleanup:

λ az container delete --name feilascontainer2 --resource-group feilasresourceswesteu
λ az container delete --name feilascontainer3 --resource-group feilasresourceswesteu

Create a new image after modifying my index.js to listen to port 80 instead of 3000.

docker build -t johnkors/feilas:v1.1 .
λ az container create --name feilascontainer4 --image johnkors/feilas:v1.1 --resource-group  feilasresourceswesteu --ip-address public

Seems not all content was being copied into the container, so had to modify the COPY cmd in the Dockerfile to omit the /* in the folder.

After doing that, recreating the image as v1.4 - it works!

λ az container create --name feilascontainer8 --image johnkors/feilas:v1.4 --resource-group  feilasresourceswesteu --ip-address public
λ  az container show --name feilascontainer8 --resource-group  feilasresourceswesteu
{
  "containers": [
    {
      "command": null,
      "environmentVariables": [],
      "image": "johnkors/feilas:v1.4",
      "instanceView": {
        "currentState": {
          "detailStatus": "",
          "exitCode": null,
          "finishTime": null,
          "startTime": "2017-08-04T12:23:39+00:00",
          "state": "Running"
        },
        "events": [
        
        ],
        "previousState": null,
        "restartCount": 0
      },
      "name": "feilascontainer8",
      "ports": [
        {
          "port": 80
        }
      ],
      "resources": {
        "limits": null,
        "requests": {
          "cpu": 1.0,
          "memoryInGb": 1.5
        }
      },
      "volumeMounts": null
    }
  ],
  "id": "/subscriptions/be95d17f-ed23-4a74-b61f-56d51845f744/resourceGroups/feilasresourceswesteu/providers/Microsoft.ContainerInstance/containerGroups/f
eilascontainer8",
  "imageRegistryCredentials": null,
  "ipAddress": {
    "ip": "104.47.151.116",
    "ports": [
      {
        "port": 80,
        "protocol": "TCP"
      }
    ]
  },
  "location": "westeurope",
  "name": "feilascontainer8",
  "osType": "Linux",
  "provisioningState": "Succeeded",
  "resourceGroup": "feilasresourceswesteu",
  "restartPolicy": null,
  "state": "Running",
  "tags": null,
  "type": "Microsoft.ContainerInstance/containerGroups",
  "volumes": null
}

Browse to 104.47.151.116 for the live app!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment