2014-02-12 04:04:39 +00:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2015-04-11 00:05:21 +00:00
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2014-05-02 23:59:28 +00:00
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2014-02-12 04:04:39 +00:00
|
|
|
)
|
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
// DecodeHostConfig creates a HostConfig based on the specified Reader.
|
|
|
|
// It assumes the content of the reader will be JSON, and decodes it.
|
2015-12-18 18:36:17 +00:00
|
|
|
func DecodeHostConfig(src io.Reader) (*container.HostConfig, error) {
|
2015-04-11 00:05:21 +00:00
|
|
|
decoder := json.NewDecoder(src)
|
|
|
|
|
2015-05-14 14:39:44 +00:00
|
|
|
var w ContainerConfigWrapper
|
2015-04-11 00:05:21 +00:00
|
|
|
if err := decoder.Decode(&w); err != nil {
|
|
|
|
return nil, err
|
2014-07-10 21:51:15 +00:00
|
|
|
}
|
2014-08-04 23:14:43 +00:00
|
|
|
|
2015-07-09 22:12:36 +00:00
|
|
|
hc := w.getHostConfig()
|
2015-04-11 00:05:21 +00:00
|
|
|
return hc, nil
|
2014-02-12 04:04:39 +00:00
|
|
|
}
|
2015-07-09 22:12:36 +00:00
|
|
|
|
|
|
|
// SetDefaultNetModeIfBlank changes the NetworkMode in a HostConfig structure
|
|
|
|
// to default if it is not populated. This ensures backwards compatibility after
|
|
|
|
// the validation of the network mode was moved from the docker CLI to the
|
|
|
|
// docker daemon.
|
2015-12-18 18:36:17 +00:00
|
|
|
func SetDefaultNetModeIfBlank(hc *container.HostConfig) *container.HostConfig {
|
2015-07-09 22:12:36 +00:00
|
|
|
if hc != nil {
|
2015-12-18 18:36:17 +00:00
|
|
|
if hc.NetworkMode == container.NetworkMode("") {
|
|
|
|
hc.NetworkMode = container.NetworkMode("default")
|
2015-07-09 22:12:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return hc
|
|
|
|
}
|