docker-container: allow using host network

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
pull/122/head
Tonis Tiigi 6 years ago
parent 75b80c277f
commit bcc882cbf1

@ -27,6 +27,7 @@ var buildkitImage = "moby/buildkit:master" // TODO: make this verified and confi
type Driver struct { type Driver struct {
driver.InitConfig driver.InitConfig
factory driver.Factory factory driver.Factory
netMode string
} }
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error { func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
@ -70,9 +71,13 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
} }
if err := l.Wrap("creating container "+d.Name, func() error { if err := l.Wrap("creating container "+d.Name, func() error {
_, err := d.DockerAPI.ContainerCreate(ctx, cfg, &container.HostConfig{ hc := &container.HostConfig{
Privileged: true, Privileged: true,
}, &network.NetworkingConfig{}, d.Name) }
if d.netMode != "" {
hc.NetworkMode = container.NetworkMode(d.netMode)
}
_, err := d.DockerAPI.ContainerCreate(ctx, cfg, hc, &network.NetworkingConfig{}, d.Name)
if err != nil { if err != nil {
return err return err
} }

@ -37,8 +37,20 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
if cfg.DockerAPI == nil { if cfg.DockerAPI == nil {
return nil, errors.Errorf("%s driver requires docker API access", f.Name()) return nil, errors.Errorf("%s driver requires docker API access", f.Name())
} }
d := &Driver{factory: f, InitConfig: cfg}
for k, v := range cfg.DriverOpts {
switch k {
case "network":
d.netMode = v
if v == "host" {
d.InitConfig.BuildkitFlags = append(d.InitConfig.BuildkitFlags, "--allow-insecure-entitlement=network.host")
}
default:
return nil, errors.Errorf("invalid driver option %s for docker-container driver")
}
}
return &Driver{factory: f, InitConfig: cfg}, nil return d, nil
} }
func (f *factory) AllowsInstances() bool { func (f *factory) AllowsInstances() bool {

Loading…
Cancel
Save