@@ -57,7 +57,6 @@ module Docker.Client.Types (
5757 , NetworkOptions(..)
5858 , Mount(..)
5959 , PortBinding(..)
60− , PortBindings(..)
6160 , HostPort(..)
6261 , RetryCount
6362 , RestartPolicy(..)
@@ -443,7 +442,7 @@ data NetworkSettings = NetworkSettings {
443442 , networkSettingsHairpinMode :: Bool
444443 , networkSettingsLinkLocalIPv6Address :: Text
445444 , networkSettingsLinkLocalIPv6PrefixLen :: Int
446− , networkSettingsPorts :: PortBindings
445+ , networkSettingsPorts :: [PortBinding]
447446 , networkSettingsSandboxKey :: Text
448447 , networkSettingsSecondaryIPAddresses :: Maybe [Text] -- TODO: 1.24 spec is unclear
449448 , networkSettingsSecondaryIPv6Addresses :: Maybe [Text] -- TODO: 1.24 spec is unclear
@@ -615,7 +614,7 @@ defaultHostConfig = HostConfig {
615614 , containerIDFile=Nothing
616615 , logConfig=LogDriverConfig JsonFile Nothing
617616 , networkMode=Bridge
618− , portBindings=PortBindings []
617+ , portBindings=[]
619618 , restartPolicy=RestartOff
620619 , volumeDriver=Nothing
621620 , volumesFrom=[]
@@ -914,13 +913,6 @@ instance FromJSON PortType where
914913-- interface like `127.0.0.1`.
915914-- __NOTE__: We should disallow duplicate port bindings as the ToJSON
916915-- instance will only send the last one.
917−newtype PortBindings = PortBindings [PortBinding]
918− deriving (Eq, Show)
919−
920−instance Monoid PortBindings where
921− mempty = PortBindings []
922− mappend (PortBindings p1) (PortBindings p2) = PortBindings (p1 ++ p2)
923−
924916-- { <port>/<protocol>: [{ "HostPort": "<port>" }] }
925917data PortBinding = PortBinding {
926918 containerPort :: Port
@@ -971,19 +963,14 @@ addVolumeFrom vf c = c{hostConfig=hc{volumesFrom=oldvfs <> [vf]}}
971963-- Example:
972964--
973965-- >>> let pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
974−-- >>> addPortBinding (defaultCreateOpts "nginx:latest") pb
966+-- >>> addPortBinding pb $ defaultCreateOpts "nginx:latest"
975967addPortBinding :: PortBinding -> CreateOpts -> CreateOpts
976−addPortBinding pb c = c{hostConfig=hc{portBindings=pbs <> PortBindings [pb]}}
968+addPortBinding pb c = c{hostConfig=hc{portBindings=pbs <> [pb]}}
977969 where hc = hostConfig c
978970 pbs = portBindings $ hostConfig c
979971
980−instance ToJSON PortBinding where
981− toJSON (PortBinding {..}) = object [portAndType2Text containerPort portType .= hostPorts]
982−
983−instance FromJSON PortBindings where
984− parseJSON (JSON.Object o) = do
985− PortBindings <$> HM.foldlWithKey' f (return []) o
986−
972+instance FromJSON [PortBinding] where
973+ parseJSON (JSON.Object o) = HM.foldlWithKey' f (return []) o
987974 where
988975 f accM k v = case T.split (== '/') k of
989976 [port', portType'] -> do
@@ -996,9 +983,9 @@ instance FromJSON PortBindings where
996983 fail "Could not parse PortBindings"
997984 parseJSON _ = fail "PortBindings is not an object"
998985
999−instance ToJSON PortBindings where
1000− toJSON (PortBindings []) = JSON.Object HM.empty
1001− toJSON (PortBindings (p:ps)) = JSON.Object $ foldl f HM.empty (p:ps)
986+instance ToJSON [PortBinding] where
987+ toJSON [] = JSON.Object HM.empty
988+ toJSON (p:ps) = JSON.Object $ foldl f HM.empty (p:ps)
1002989 where mKey p = portAndType2Text (containerPort p) (portType p)
1003990 mVal p = toJSON $ hostPorts p
1004991 f acc p = HM.insert (mKey p) (mVal p) acc
@@ -1054,7 +1041,7 @@ data HostConfig = HostConfig
10541041 , containerIDFile :: Maybe FilePath -- 1.24: Only in responses, not create
10551042 , logConfig :: LogDriverConfig
10561043 , networkMode :: NetworkMode
1057− , portBindings :: PortBindings
1044+ , portBindings :: [PortBinding]
10581045 , restartPolicy :: RestartPolicy
10591046 , volumeDriver :: Maybe Text
10601047 , volumesFrom :: [VolumeFrom]