Skip to content

Instantly share code, notes, and snippets.

@Xe
Last active September 1, 2015 03:14
Show Gist options
  • Select an option

  • Save Xe/41d57dd60ab01b33ffb8 to your computer and use it in GitHub Desktop.

Select an option

Save Xe/41d57dd60ab01b33ffb8 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import System.IO.Streams (InputStream, OutputStream, stdout)
import qualified System.IO.Streams as Streams
import qualified Data.ByteString as S
import Network.Http.Client
main :: IO ()
main = do
c <- openConnectionUnix "/var/run/docker.sock"
let q = buildRequest1 $ do
http GET "/v1.12/containers/json"
setAccept "application/json"
sendRequest c q emptyBody
receiveResponse c (\p i -> do
let status = getStatusCode p
case status of
200 -> return ()
otherwise -> error $ "Failed! Status code " ++ (show status)
xm <- Streams.read i
case xm of
Just x -> S.putStr x)
closeConnection c
[
{
"Command": "crate",
"Created": 1440093436,
"Id": "e1778874f60b5a4ff18a122606bfe2ba45ba41e2ba71b27ce8de1e2dd403aabd",
"Image": "crate",
"Labels": {},
"Names": [
"/crate"
],
"Ports": [
{
"PrivatePort": 4300,
"Type": "tcp"
},
{
"IP": "0.0.0.0",
"PrivatePort": 4200,
"PublicPort": 4200,
"Type": "tcp"
}
],
"Status": "Up About an hour"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment