@@ -796,7 +796,11 @@ instance ToJSON NetworkMode where
796 toJSON Host = JSON.String "host"
796 toJSON Host = JSON.String "host"
797 toJSON NetworkDisabled = JSON.String "none"
797 toJSON NetworkDisabled = JSON.String "none"
799−data PortType = TCP | UDP deriving (Eq, Show, Generic, Read, Ord)
799+data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
801+instance Show PortType where
801instance ToJSON PortType where
805instance ToJSON PortType where
802 toJSON TCP = "tcp"
806 toJSON TCP = "tcp"
@@ -821,6 +825,8 @@ instance FromJSON PortType where
821-- host system s that the service running in the container can be accessed from
825-- host system s that the service running in the container can be accessed from
822-- the outside world. We either map a port onto all interfaces (default) or onto a specific
826-- the outside world. We either map a port onto all interfaces (default) or onto a specific
823-- interface like `127.0.0.1`.
827-- interface like `127.0.0.1`.
828+-- __NOTE__: We should disallow duplicate port bindings as the ToJSON
829+-- instnace will only send the last one.
824newtype PortBindings = PortBindings [PortBinding]
830newtype PortBindings = PortBindings [PortBinding]
825 deriving (Eq, Show)
831 deriving (Eq, Show)
@@ -856,7 +862,10 @@ instance FromJSON PortBindings where
857instance ToJSON PortBindings where
863instance ToJSON PortBindings where
858 toJSON (PortBindings []) = JSON.Object HM.empty
864 toJSON (PortBindings []) = JSON.Object HM.empty
859− toJSON (PortBindings (p:ps)) = toJSON (p:ps)
865+ toJSON (PortBindings (p:ps)) = JSON.Object $ foldl f HM.empty (p:ps)
866+ where mKey p = portAndType2Text (containerPort p) (portType p)
867+ mVal p = toJSON $ hostPorts p
868+ f acc p = HM.insert (mKey p) (mVal p) acc
861data HostPort = HostPort {
870data HostPort = HostPort {
862 hostIp :: Text
871 hostIp :: Text