Skip to content

Commit c7964b5

Browse files
Eneman DonatienEneman Donatien
Eneman Donatien
authored and
Eneman Donatien
committed
[ENH] ✨ add docker driver --net options
1 parent 56c7201 commit c7964b5

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ containerRunOptions:
300300
user: "root" # set the --user/-u flag
301301
privileged: true # set the --privileged flag (default: false)
302302
allocateTty: true # set the --tty flag (default: false)
303+
network: "bridge" # set the --net flag (default: bridge)
303304
envFile: path/to/.env # load environment variables from file and pass to container (equivalent to --env-file)
304305
envVars: # if not empty, read each envVar from the environment and pass to test (equivalent to --env/e)
305306
- SECRET_KEY_FOO

pkg/drivers/docker_driver.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import (
1919
"bufio"
2020
"bytes"
2121
"fmt"
22-
"github.com/joho/godotenv"
2322
"io"
2423
"os"
2524
"path"
2625
"path/filepath"
2726
"strings"
2827

28+
"github.com/joho/godotenv"
29+
2930
"github.com/pkg/errors"
3031
"github.com/sirupsen/logrus"
3132

@@ -70,13 +71,15 @@ func (d *DockerDriver) hostConfig() *docker.HostConfig {
7071
Binds: d.runOpts.BindMounts,
7172
Privileged: d.runOpts.Privileged,
7273
Runtime: d.runtime,
74+
NetworkMode: d.runOpts.Network,
7375
}
7476
}
7577
if d.runOpts.IsSet() {
7678
return &docker.HostConfig{
7779
Capabilities: d.runOpts.Capabilities,
7880
Binds: d.runOpts.BindMounts,
7981
Privileged: d.runOpts.Privileged,
82+
NetworkMode: d.runOpts.Network,
8083
}
8184
}
8285
if d.runtime != "" {
@@ -335,9 +338,13 @@ func (d *DockerDriver) runAndCommit(env []string, command []string) (string, err
335338
HostConfig: d.hostConfig(),
336339
NetworkingConfig: nil,
337340
}
341+
338342
if d.runOpts.IsSet() && len(d.runOpts.User) > 0 {
339343
createOpts.Config.User = d.runOpts.User
340344
}
345+
if d.runOpts.IsSet() && len(d.runOpts.Network) > 0 {
346+
createOpts.HostConfig.NetworkMode = d.runOpts.Network
347+
}
341348
container, err := d.cli.CreateContainer(createOpts)
342349
if err != nil {
343350
return "", errors.Wrap(err, "Error creating container")

pkg/types/unversioned/types.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type ContainerRunOptions struct {
5252
EnvFile string `yaml:"envFile"`
5353
Capabilities []string
5454
BindMounts []string `yaml:"bindMounts"`
55+
Network string `yaml:"network"`
5556
}
5657

5758
func (opts *ContainerRunOptions) IsSet() bool {
@@ -61,6 +62,7 @@ func (opts *ContainerRunOptions) IsSet() bool {
6162
len(opts.EnvFile) > 0 ||
6263
(opts.EnvVars != nil && len(opts.EnvVars) > 0) ||
6364
(opts.Capabilities != nil && len(opts.Capabilities) > 0) ||
65+
len(opts.Network) != 0 ||
6466
(opts.BindMounts != nil && len(opts.BindMounts) > 0)
6567
}
6668

0 commit comments

Comments
 (0)