Can you create a droplet from Ubuntu 14.04 x64 or with Docker application using API?

July 17, 2014 2k views

I've been playing with the API and using DO as a Vagrant Provider, but I can't seem to find a way to create a droplet from Ubuntu 14.04 x64 (curl -u {api-key} https://api.digitalocean.com/v2/images doesn't include Ubuntu 14.04 in the list of available images). I also wondered if it's possible to reference the "application" images DO provides in their web UI via the API (e.g., create a new image from their "Docker 1.0 on Ubuntu 14.04 x64" application instead of having to build it on your own).

Anyone have an example of creating an Ubuntu 14.04 x64 droplet using Vagrant? Or otherwise using the API that might help me figure out how to make it work through Vagrant?

1 Answer

Both images are returned by the /images API call:

    {
      "id":3240036,
      "name":"Ubuntu 14.04 x64",
      "distribution":"Ubuntu",
      "slug":"ubuntu-14-04-x64",
      "public":true,
      "regions":[
        "nyc1",
        "ams1",
        "sfo1",
        "nyc2",
        "ams2",
        "sgp1",
        "lon1"
      ],
      "created_at":"2014-04-18T15:59:36Z"
    }
    {
      "id":4970653,
      "name":"Docker 1.1.1 on Ubuntu 14.04",
      "distribution":"Ubuntu",
      "slug":null,
      "public":true,
      "regions":[
        "nyc1",
        "ams1",
        "sfo1",
        "nyc2",
        "ams2",
        "sgp1",
        "lon1"
      ],
      "created_at":"2014-07-16T20:00:38Z"
    }

At the very bottom of the response there are pagination links (it might be different for your account depending on how many snapshots you have), so just keep changing the URL until you get the image you need:

  "links":{
    "pages":{
      "last":"https://api.digitalocean.com/v2/images?page=3",
      "next":"https://api.digitalocean.com/v2/images?page=2"
    }

You're most likely going to find the Docker image in the last page as it was just updated a few seconds ago. You can also use the image's slug instead of its ID: ubuntu-14-04-x64.

P.S.: Since you're using curl, you can use the Authorization header instead of HTTP basic auth:

curl -H "Authorization: Bearer token" https://api.digitalocean.com/v2/images
Have another answer? Share your knowledge.