@@ -58,44 +58,80 @@ parseResponse (Right response) =
58 Right r ->
58 Right r ->
59 return $ Right r
59 return $ Right r
61+-- | Gets the version of the docker engine remote API.
61getDockerVersion :: forall m. Monad m => DockerT m (Either DockerError DockerVersion)
62getDockerVersion :: forall m. Monad m => DockerT m (Either DockerError DockerVersion)
62getDockerVersion = requestHelper GET VersionEndpoint >>= parseResponse
63getDockerVersion = requestHelper GET VersionEndpoint >>= parseResponse
65+-- | Lists all running docker containers. Pass in defaultListOpts {all
66+-- = True} to get a list of stopped containers as well.
64listContainers :: forall m. Monad m => ListOpts -> DockerT m (Either DockerError [Container])
67listContainers :: forall m. Monad m => ListOpts -> DockerT m (Either DockerError [Container])
65listContainers opts = requestHelper GET (ListContainersEndpoint opts) >>= parseResponse
68listContainers opts = requestHelper GET (ListContainersEndpoint opts) >>= parseResponse
70+-- | Lists all docker images.
67listImages :: forall m. Monad m => ListOpts -> DockerT m (Either DockerError [Image])
71listImages :: forall m. Monad m => ListOpts -> DockerT m (Either DockerError [Image])
68listImages opts = requestHelper GET (ListImagesEndpoint opts) >>= parseResponse
72listImages opts = requestHelper GET (ListImagesEndpoint opts) >>= parseResponse
74+-- | Creates a docker container but does *not* start it. See
75+-- "CreateOpts" for a list of options and you can use "defaultCreateOpts"
76+-- for some sane defaults.
70createContainer :: forall m. Monad m => CreateOpts -> DockerT m (Either DockerError ContainerID)
77createContainer :: forall m. Monad m => CreateOpts -> DockerT m (Either DockerError ContainerID)
71createContainer opts = requestHelper POST (CreateContainerEndpoint opts) >>= parseResponse
78createContainer opts = requestHelper POST (CreateContainerEndpoint opts) >>= parseResponse
73−-- TODO: Is this the correct return type? XXX
80+-- | Start a container from a given "ContainerID" that we get from
74−-- convert status code to unit or error
81+-- "createContainer". See "StartOpts" for a list of configuration options
82+-- for starting a container. Use "defaultStartOpts" for sane defaults.
75startContainer :: forall m. Monad m => StartOpts -> ContainerID -> DockerT m (Either DockerError ())
83startContainer :: forall m. Monad m => StartOpts -> ContainerID -> DockerT m (Either DockerError ())
76startContainer sopts cid = requestUnit POST $ StartContainerEndpoint sopts cid
84startContainer sopts cid = requestUnit POST $ StartContainerEndpoint sopts cid
86+-- | Attempts to stop a container with the given "ContainerID" gracefully
88+-- The docker daemon will wait for the given "Tiemout" and then send
89+-- a SIGKILL killing the container.
78stopContainer :: forall m. Monad m => Timeout -> ContainerID -> DockerT m (Either DockerError ())
90stopContainer :: forall m. Monad m => Timeout -> ContainerID -> DockerT m (Either DockerError ())
79stopContainer t cid = requestUnit POST $ StopContainerEndpoint t cid
91stopContainer t cid = requestUnit POST $ StopContainerEndpoint t cid
93+-- | Sends a "Signal" to the container with the given "ContainerID". Same
94+-- as "stopContainer" but you choose the signal directly.
81killContainer :: forall m. Monad m => Signal -> ContainerID -> DockerT m (Either DockerError ())
95killContainer :: forall m. Monad m => Signal -> ContainerID -> DockerT m (Either DockerError ())
82killContainer s cid = requestUnit POST $ KillContainerEndpoint s cid
96killContainer s cid = requestUnit POST $ KillContainerEndpoint s cid
98+-- | Restarts a container with the given "ContainerID".
84restartContainer :: forall m. Monad m => Timeout -> ContainerID -> DockerT m (Either DockerError ())
99restartContainer :: forall m. Monad m => Timeout -> ContainerID -> DockerT m (Either DockerError ())
85restartContainer t cid = requestUnit POST $ RestartContainerEndpoint t cid
100restartContainer t cid = requestUnit POST $ RestartContainerEndpoint t cid
102+-- | Pauses a container with the given "ContainerID"
87pauseContainer :: forall m. Monad m => ContainerID -> DockerT m (Either DockerError ())
103pauseContainer :: forall m. Monad m => ContainerID -> DockerT m (Either DockerError ())
88pauseContainer cid = requestUnit POST $ PauseContainerEndpoint cid
104pauseContainer cid = requestUnit POST $ PauseContainerEndpoint cid
106+-- | Unpauses a container with the given "ContainerID".
90unpauseContainer :: forall m. Monad m => ContainerID -> DockerT m (Either DockerError ())
107unpauseContainer :: forall m. Monad m => ContainerID -> DockerT m (Either DockerError ())
91unpauseContainer cid = requestUnit GET $ UnpauseContainerEndpoint cid
108unpauseContainer cid = requestUnit GET $ UnpauseContainerEndpoint cid
110+-- | Deletes a container with the given "ContainerID".
111+-- See "DeleteOpts" for options and use "defaultDeleteOpts" for sane
93deleteContainer :: forall m. Monad m => DeleteOpts -> ContainerID -> DockerT m (Either DockerError ())
113deleteContainer :: forall m. Monad m => DeleteOpts -> ContainerID -> DockerT m (Either DockerError ())
94deleteContainer dopts cid = requestUnit DELETE $ DeleteContainerEndpoint dopts cid
114deleteContainer dopts cid = requestUnit DELETE $ DeleteContainerEndpoint dopts cid
116+-- | Gets "ContainerDetails" for a given "ContainerID".
96inspectContainer :: forall m . Monad m => ContainerID -> DockerT m (Either DockerError ContainerDetails)
117inspectContainer :: forall m . Monad m => ContainerID -> DockerT m (Either DockerError ContainerDetails)
97inspectContainer cid = requestHelper GET (InspectContainerEndpoint cid) >>= parseResponse
118inspectContainer cid = requestHelper GET (InspectContainerEndpoint cid) >>= parseResponse
120+-- | Get's container's logs for a given "ContainerID".
121+-- This will only work with the "JsonFile" "LogDriverType" as the other driver types disable
122+-- this endpoint and it will return a DockerError.
124+-- See "LogOpts" for options that you can pass and
125+-- "defaultLogOpts" for sane defaults.
127+-- __NOTE__: Currently streaming logs is
128+-- not supported and this function will fetch the entire log that the
129+-- container produced in the json-file on disk. Depending on the logging
130+-- setup of the process in your container this can be a significant amount
131+-- which might block your application...so use with caution.
133+-- The recommended method is to use one of the other "LogDriverType"'s available (like
134+-- syslog) for creating your containers.
99getContainerLogs :: forall m. Monad m => LogOpts -> ContainerID -> DockerT m (Either DockerError BSL.ByteString)
135getContainerLogs :: forall m. Monad m => LogOpts -> ContainerID -> DockerT m (Either DockerError BSL.ByteString)
100getContainerLogs logopts cid = fmap responseBody <$> requestHelper GET (ContainerLogsEndpoint logopts False cid)
136getContainerLogs logopts cid = fmap responseBody <$> requestHelper GET (ContainerLogsEndpoint logopts False cid)