IMMENSE.LY

IT’S THAT BIG

Something New About Sockets

I just found out something really cool about curl.  Actually, it’s so cool that at first I couldn’t believe that I didn’t know about it, but apparently it’s a new thing.  There is now a “–unix-socket” command which will allow you to pass HTTP through a unix socket. This might not initially seem like a big deal, but it’s extremely handy when you’ve set up HTTP pass-through a unix socket to something like Gunicorn if you’re in Django land.  It’s also particularly handy for debugging the Docker API which you can get to at /var/run/docker.sock. Here’s an example:

$ curl -s --unix-socket /var/run/docker.sock http://localhost/images/json | jq -r "."
[
  {
    "Id": "sha256:aeff5a9860a391e0313f68c37ed368e524f53d6ecb6be0f2b70ef3922ebcda28",
    "ParentId": "",
    "RepoTags": [
      "gcr.io/tensorflow/tensorflow:latest"
    ],
    "RepoDigests": null,
    "Created": 1461181967,
    "Size": 714212803,
    "VirtualSize": 714212803,
    "Labels": null,
  }
]

That gives you a lot more data than if you were trying to directly parse “docker images”, plus makes it super easy to debug what’s going on under the covers.