on master help sign in
Makes addBind function consistent with others
18482fcDeni Bertovic
examples/Example.hs+2−1
@@ -21,7 +21,8 @@ stopNginxContainer cid = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
21runPostgresContainer :: IO ContainerID
21runPostgresContainer :: IO ContainerID
22runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
22runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
23 let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
23 let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
24+ let b = Bind "/tmp" "/tmp" Nothing
24− let myCreateOpts = addBinds [Bind "/tmp" "/tmp" Nothing] $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
25+ let myCreateOpts = addBind b $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
25 cid <- createContainer myCreateOpts Nothing
26 cid <- createContainer myCreateOpts Nothing
26 case cid of
27 case cid of
27 Left err -> error $ show err
28 Left err -> error $ show err
src/Docker/Client/Types.hs+6−3
@@ -78,7 +78,7 @@ module Docker.Client.Types (
78 , DeviceWeight(..)
78 , DeviceWeight(..)
79 , DeviceRate(..)
79 , DeviceRate(..)
80 , addPortBinding
80 , addPortBinding
81− , addBinds
81+ , addBind
82 ) where
82 ) where
83
83
84import Data.Aeson (FromJSON, ToJSON, genericParseJSON,
84import Data.Aeson (FromJSON, ToJSON, genericParseJSON,
@@ -926,9 +926,12 @@ portAndType2Text :: Port -> PortType -> Text
926portAndType2Text p t = (T.pack $ show p) <> "/" <> (T.pack $ show t)
926portAndType2Text p t = (T.pack $ show p) <> "/" <> (T.pack $ show t)
927
927
928
928
929+-- | A helper function to more easily add a bind mount to existing
930+-- "CreateOpts" records.
929−addBinds :: [Bind] -> CreateOpts -> CreateOpts
931+addBind :: Bind -> CreateOpts -> CreateOpts
930−addBinds bs c = c{hostConfig=hc{binds=bs}}
932+addBind b c = c{hostConfig=hc{binds=obs <> [b]}}
931 where hc = hostConfig c
933 where hc = hostConfig c
934+ obs = binds $ hostConfig c
932
935
933-- | A convenience function that adds PortBindings to and exiting
936-- | A convenience function that adds PortBindings to and exiting
934-- "CreateOpts" record. Useful with 'defaultCreateOpts'
937-- "CreateOpts" record. Useful with 'defaultCreateOpts'