on master help sign in
Merge branch 'dev' of https://github.com/jprider63/docker-hs into dev
commit3d28152cf855519ee39a8053120d1039f548ee9e authorDeni Bertovic <deni@denibertovic.com> dateTue 23 Aug 2016, 13:52 (10 years ago) parent916a045c738795
3 files changed+48−24
src/Docker/Client.hs+27−3 src/Docker/Client/Api.hs+20−20 src/Docker/Client/Types.hs+1−1
src/Docker/Client.hs+27−3
@@ -9,9 +9,9 @@ Maintainer : deni@denibertovic.com
99Stability : experimental
1010Portability : POSIX
1111
12−Getting started
12+= Getting started
1313
14−* Creating a container:
14+Creating a container:
1515
1616We're going to create a nginx container and we're going to map port @80@ from within the container to port @8000@ on
1717the host.
@@ -51,11 +51,35 @@ stopNginxContainer cid = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
5151
5252>>> stopNginxContainer cid
5353
54−* Get Docker API Version:
54+= Get Docker API Version
5555
5656>>> runDockerT (defaultClientOpts, defaultHttpHandler) $ getDockerVersion
5757Right (DockerVersion {version = "1.12.0", apiVersion = "1.24", gitCommit = "8eab29e", goVersion = "go1.6.3", os = "linux", arch = "amd64", kernelVersion = "4.6.0-1-amd64", buildTime = "2016-07-28T21:46:40.664812891+00:00"})
5858
59+= Setup SSL Authentication
60+
61+Let's create a custom 'HttpHandler' that uses a client's certificate and private key for SSL authentication.
62+It also accepts a self-signed CA certificate which is specified via 'clientParamsSetCA'.
63+This handler can replace 'defaultHttpHandler' in the arguments to 'runDockerT'.
64+
65+@
66+let host = "domain.name"
67+let port = fromInteger 4000
68+let privKey = "path\/to\/private\/key"
69+let cert = "path\/to\/certificate"
70+let ca = "path\/to\/CA"
71+paramsE <- clientParamsWithClientAuthentication host port privKey cert
72+case paramsE of
73+ Left err ->
74+ error err
75+ Right params' -> do
76+ params <- clientParamsSetCA params' ca
77+ settings <- HTTP.mkManagerSettings (TLSSettings params) Nothing
78+ manager <- newManager settings
79+ return $ httpHandler manager
80+@
81+
82+
5983-}
6084module Docker.Client (
6185 -- * Client functions
src/Docker/Client/Api.hs+20−20
@@ -65,8 +65,8 @@ parseResponse (Right response) =
6565getDockerVersion :: forall m. Monad m => DockerT m (Either DockerError DockerVersion)
6666getDockerVersion = requestHelper GET VersionEndpoint >>= parseResponse
6767
68−-- | Lists all running docker containers. Pass in 'defaultListOpts' {all
69−-- = True} to get a list of stopped containers as well.
68+-- | Lists all running docker containers. Pass in @'defaultListOpts' {all
69+-- = True}@ to get a list of stopped containers as well.
7070listContainers :: forall m. Monad m => ListOpts -> DockerT m (Either DockerError [Container])
7171listContainers opts = requestHelper GET (ListContainersEndpoint opts) >>= parseResponse
7272
@@ -74,57 +74,57 @@ listContainers opts = requestHelper GET (ListContainersEndpoint opts) >>= parseR
7474listImages :: forall m. Monad m => ListOpts -> DockerT m (Either DockerError [Image])
7575listImages opts = requestHelper GET (ListImagesEndpoint opts) >>= parseResponse
7676
77−-- | Creates a docker container but does *not* start it. See
78−-- "CreateOpts" for a list of options and you can use 'defaultCreateOpts'
77+-- | Creates a docker container but does __not__ start it. See
78+-- 'CreateOpts' for a list of options and you can use 'defaultCreateOpts'
7979-- for some sane defaults.
8080createContainer :: forall m. Monad m => CreateOpts -> DockerT m (Either DockerError ContainerID)
8181createContainer opts = requestHelper POST (CreateContainerEndpoint opts) >>= parseResponse
8282
83−-- | Start a container from a given "ContainerID" that we get from
84−-- 'createContainer'. See "StartOpts" for a list of configuration options
83+-- | Start a container from a given 'ContainerID' that we get from
84+-- 'createContainer'. See 'StartOpts' for a list of configuration options
8585-- for starting a container. Use 'defaultStartOpts' for sane defaults.
8686startContainer :: forall m. Monad m => StartOpts -> ContainerID -> DockerT m (Either DockerError ())
8787startContainer sopts cid = requestUnit POST $ StartContainerEndpoint sopts cid
8888
89−-- | Attempts to stop a container with the given "ContainerID" gracefully
89+-- | Attempts to stop a container with the given 'ContainerID' gracefully
9090-- (SIGTERM).
91−-- The docker daemon will wait for the given "Tiemout" and then send
91+-- The docker daemon will wait for the given 'Timeout' and then send
9292-- a SIGKILL killing the container.
9393stopContainer :: forall m. Monad m => Timeout -> ContainerID -> DockerT m (Either DockerError ())
9494stopContainer t cid = requestUnit POST $ StopContainerEndpoint t cid
9595
96−-- | Sends a "Signal" to the container with the given "ContainerID". Same
97−-- as "stopContainer" but you choose the signal directly.
96+-- | Sends a 'Signal' to the container with the given 'ContainerID'. Same
97+-- as 'stopContainer' but you choose the signal directly.
9898killContainer :: forall m. Monad m => Signal -> ContainerID -> DockerT m (Either DockerError ())
9999killContainer s cid = requestUnit POST $ KillContainerEndpoint s cid
100100
101−-- | Restarts a container with the given "ContainerID".
101+-- | Restarts a container with the given 'ContainerID'.
102102restartContainer :: forall m. Monad m => Timeout -> ContainerID -> DockerT m (Either DockerError ())
103103restartContainer t cid = requestUnit POST $ RestartContainerEndpoint t cid
104104
105−-- | Pauses a container with the given "ContainerID"
105+-- | Pauses a container with the given 'ContainerID'.
106106pauseContainer :: forall m. Monad m => ContainerID -> DockerT m (Either DockerError ())
107107pauseContainer cid = requestUnit POST $ PauseContainerEndpoint cid
108108
109−-- | Unpauses a container with the given "ContainerID".
109+-- | Unpauses a container with the given 'ContainerID'.
110110unpauseContainer :: forall m. Monad m => ContainerID -> DockerT m (Either DockerError ())
111111unpauseContainer cid = requestUnit GET $ UnpauseContainerEndpoint cid
112112
113−-- | Deletes a container with the given "ContainerID".
113+-- | Deletes a container with the given 'ContainerID'.
114114-- See "DeleteOpts" for options and use 'defaultDeleteOpts' for sane
115115-- defaults.
116116deleteContainer :: forall m. Monad m => DeleteOpts -> ContainerID -> DockerT m (Either DockerError ())
117117deleteContainer dopts cid = requestUnit DELETE $ DeleteContainerEndpoint dopts cid
118118
119−-- | Gets "ContainerDetails" for a given "ContainerID".
119+-- | Gets 'ContainerDetails' for a given 'ContainerID'.
120120inspectContainer :: forall m . Monad m => ContainerID -> DockerT m (Either DockerError ContainerDetails)
121121inspectContainer cid = requestHelper GET (InspectContainerEndpoint cid) >>= parseResponse
122122
123−-- | Get's container's logs for a given "ContainerID".
124−-- This will only work with the "JsonFile" "LogDriverType" as the other driver types disable
125−-- this endpoint and it will return a "DockerError".
123+-- | Get's container's logs for a given 'ContainerID'.
124+-- This will only work with the 'JsonFile' 'LogDriverType' as the other driver types disable
125+-- this endpoint and it will return a 'DockerError'.
126126--
127−-- See "LogOpts" for options that you can pass and
127+-- See 'LogOpts' for options that you can pass and
128128-- 'defaultLogOpts' for sane defaults.
129129--
130130-- __NOTE__: Currently streaming logs is
@@ -133,7 +133,7 @@ inspectContainer cid = requestHelper GET (InspectContainerEndpoint cid) >>= pars
133133-- setup of the process in your container this can be a significant amount
134134-- which might block your application...so use with caution.
135135--
136−-- The recommended method is to use one of the other "LogDriverType"'s available (like
136+-- The recommended method is to use one of the other 'LogDriverType's available (like
137137-- syslog) for creating your containers.
138138getContainerLogs :: forall m. Monad m => LogOpts -> ContainerID -> DockerT m (Either DockerError BSL.ByteString)
139139getContainerLogs logopts cid = fmap responseBody <$> requestHelper GET (ContainerLogsEndpoint logopts False cid)
src/Docker/Client/Types.hs+1−1
@@ -844,7 +844,7 @@ instance FromJSON PortType where
844844-- the outside world. We either map a port onto all interfaces (default) or onto a specific
845845-- interface like `127.0.0.1`.
846846-- __NOTE__: We should disallow duplicate port bindings as the ToJSON
847−-- instnace will only send the last one.
847+-- instance will only send the last one.
848848newtype PortBindings = PortBindings [PortBinding]
849849 deriving (Eq, Show)
850850