Allow privileged mode in docker interface
Change-Id: I12e7a895c5ccd228a3bb1a2ef3588be96893ae36
This commit is contained in:
parent
3ae387e9f2
commit
4671ea7f74
@ -45,10 +45,13 @@ type Container interface {
|
|||||||
|
|
||||||
// RunCommandOptions options for RunCommand
|
// RunCommandOptions options for RunCommand
|
||||||
type RunCommandOptions struct {
|
type RunCommandOptions struct {
|
||||||
|
Privileged bool
|
||||||
|
|
||||||
Cmd []string
|
Cmd []string
|
||||||
EnvVars []string
|
EnvVars []string
|
||||||
VolumeMounts []string
|
VolumeMounts []string
|
||||||
Input io.Reader
|
|
||||||
|
Input io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainer returns instance of Container interface implemented by particular driver
|
// NewContainer returns instance of Container interface implemented by particular driver
|
||||||
|
@ -169,23 +169,24 @@ func (c *DockerContainer) getCmd(cmd []string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getConfig creates configuration structures for Docker API client.
|
// getConfig creates configuration structures for Docker API client.
|
||||||
func (c *DockerContainer) getConfig(
|
func (c *DockerContainer) getConfig(opts RunCommandOptions) (container.Config, container.HostConfig, error) {
|
||||||
cmd []string,
|
cmd, err := c.getCmd(opts.Cmd)
|
||||||
volumeMounts []string,
|
if err != nil {
|
||||||
envVars []string,
|
return container.Config{}, container.HostConfig{}, err
|
||||||
) (container.Config, container.HostConfig) {
|
}
|
||||||
cCfg := container.Config{
|
cCfg := container.Config{
|
||||||
Image: c.imageURL,
|
Image: c.imageURL,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
AttachStdin: true,
|
AttachStdin: true,
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
Env: envVars,
|
Env: opts.EnvVars,
|
||||||
Tty: true,
|
Tty: true,
|
||||||
}
|
}
|
||||||
hCfg := container.HostConfig{
|
hCfg := container.HostConfig{
|
||||||
Binds: volumeMounts,
|
Binds: opts.VolumeMounts,
|
||||||
|
Privileged: opts.Privileged,
|
||||||
}
|
}
|
||||||
return cCfg, hCfg
|
return cCfg, hCfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getImageID return ID of container image specified by URL. Method executes
|
// getImageID return ID of container image specified by URL. Method executes
|
||||||
@ -241,13 +242,11 @@ func (c *DockerContainer) ImagePull() error {
|
|||||||
|
|
||||||
// RunCommand executes specified command in Docker container. Method handles
|
// RunCommand executes specified command in Docker container. Method handles
|
||||||
// container STDIN and volume binds
|
// container STDIN and volume binds
|
||||||
func (c *DockerContainer) RunCommand(opts RunCommandOptions) error {
|
func (c *DockerContainer) RunCommand(opts RunCommandOptions) (err error) {
|
||||||
realCmd, err := c.getCmd(opts.Cmd)
|
containerConfig, hostConfig, err := c.getConfig(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
containerConfig, hostConfig := c.getConfig(realCmd, opts.VolumeMounts, opts.EnvVars)
|
|
||||||
resp, err := c.dockerClient.ContainerCreate(
|
resp, err := c.dockerClient.ContainerCreate(
|
||||||
c.ctx,
|
c.ctx,
|
||||||
&containerConfig,
|
&containerConfig,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user