add --network option for docker build

Signed-off-by: sandyskies <chenmingjie0828@163.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
sandyskies 2016-03-06 20:29:23 +08:00 committed by Tonis Tiigi
parent 67b85f9d26
commit 60813af7ae
10 changed files with 25 additions and 1 deletions

View file

@ -51,6 +51,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
options.CPUSetCPUs = r.FormValue("cpusetcpus")
options.CPUSetMems = r.FormValue("cpusetmems")
options.CgroupParent = r.FormValue("cgroupparent")
options.NetworkMode = r.FormValue("networkmode")
options.Tags = r.Form["t"]
options.SecurityOpt = r.Form["securityopt"]

View file

@ -141,6 +141,7 @@ type ImageBuildOptions struct {
Memory int64
MemorySwap int64
CgroupParent string
NetworkMode string
ShmSize int64
Dockerfile string
Ulimits []*units.Ulimit

View file

@ -487,6 +487,7 @@ func (b *Builder) create() (string, error) {
Isolation: b.options.Isolation,
ShmSize: b.options.ShmSize,
Resources: resources,
NetworkMode: container.NetworkMode(b.options.NetworkMode),
}
config := *b.runConfig

View file

@ -58,6 +58,7 @@ type buildOptions struct {
cacheFrom []string
compress bool
securityOpt []string
networkMode string
}
// NewBuildCommand creates a new `docker build` command
@ -105,6 +106,7 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.StringSliceVar(&options.cacheFrom, "cache-from", []string{}, "Images to consider as cache sources")
flags.BoolVar(&options.compress, "compress", false, "Compress the build context using gzip")
flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options")
flags.StringVar(&options.networkMode, "network", "default", "Connect a container to a network")
command.AddTrustedFlags(flags, true)
@ -302,6 +304,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
CacheFrom: options.cacheFrom,
SecurityOpt: options.securityOpt,
NetworkMode: options.networkMode,
}
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)

View file

@ -84,6 +84,7 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro
}
query.Set("cpusetcpus", options.CPUSetCPUs)
query.Set("networkmode", options.NetworkMode)
query.Set("cpusetmems", options.CPUSetMems)
query.Set("cpushares", strconv.FormatInt(options.CPUShares, 10))
query.Set("cpuquota", strconv.FormatInt(options.CPUQuota, 10))

View file

@ -130,6 +130,7 @@ This section lists each version from latest to oldest. Each listing includes a
[Docker Remote API v1.25](docker_remote_api_v1.25.md) documentation
* `POST /build` accepts `networkmode` parameter to specify network used during build.
* `GET /images/(name)/json` now returns `OsVersion` if populated
* `GET /info` now returns `Isolation`.
* `POST /containers/create` now takes `AutoRemove` in HostConfig, to enable auto-removal of the container on daemon side when the container's process exits.

View file

@ -1788,6 +1788,11 @@ or being killed.
passing secret values. [Read more about the buildargs instruction](../../reference/builder.md#arg)
- **shmsize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB.
- **labels** JSON map of string pairs for labels to set on the image.
- **networkmode** - Sets the networking mode for the run commands during
build. Supported standard values are: `bridge`, `host`, `none`, and
`container:<name|id>`. Any other value is taken as a custom network's
name to which this container should connect to.
**Request Headers**:

View file

@ -38,6 +38,13 @@ Options:
--label value Set metadata for an image (default [])
-m, --memory string Memory limit
--memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--network string Set the networking mode for the run commands
during build.
'bridge': use default Docker bridge
'none': no networking
'container:<name|id>': reuse another container's network stack
'host': use the Docker host network stack
'<network-name>|<network-id>': connect to a user-defined network
--no-cache Do not use cache when building the image
--pull Always attempt to pull a newer version of the image
-q, --quiet Suppress the build output and print image ID on success

View file

@ -22,6 +22,7 @@ docker-build - Build a new image from the source code at PATH
[**-t**|**--tag**[=*[]*]]
[**-m**|**--memory**[=*MEMORY*]]
[**--memory-swap**[=*LIMIT*]]
[**--network**[=*"default"*]]
[**--shm-size**[=*SHM-SIZE*]]
[**--cpu-period**[=*0*]]
[**--cpu-quota**[=*0*]]
@ -111,6 +112,9 @@ set as the **URL**, the repository is cloned locally and then sent as the contex
`k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a
unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
**--network**=*NETWORK*
**--shm-size**=*SHM-SIZE*
Size of `/dev/shm`. The format is `<number><unit>`. `number` must be greater than `0`.
Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you omit the unit, the system uses bytes.

View file

@ -388,7 +388,7 @@ string name. The name is useful when defining links (see **--link**) (or any
other place you need to identify a container). This works for both background
and foreground Docker containers.
**--net**="*bridge*"
**--network**="*bridge*"
Set the Network mode for the container
'bridge': create a network stack on the default Docker bridge
'none': no networking