summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go3
-rw-r--r--libpod/container_internal.go13
-rw-r--r--libpod/container_internal_linux.go2
-rw-r--r--libpod/options.go18
4 files changed, 34 insertions, 2 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 24a5f93af..9486986ab 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -313,6 +313,9 @@ type ContainerConfig struct {
// ExitCommand is the container's exit command.
// This Command will be executed when the container exits
ExitCommand []string `json:"exitCommand,omitempty"`
+ // LocalVolumes are the built-in volumes we get from the --volumes-from flag
+ // It picks up the built-in volumes of the container used by --volumes-from
+ LocalVolumes []string
}
// ContainerStatus returns a string representation for users
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 94cd74c09..eb9b39a02 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -1108,7 +1108,7 @@ func (c *Container) generateHosts() (string, error) {
return c.writeStringToRundir("hosts", hosts)
}
-func (c *Container) addImageVolumes(ctx context.Context, g *generate.Generator) error {
+func (c *Container) addLocalVolumes(ctx context.Context, g *generate.Generator) error {
mountPoint := c.state.Mountpoint
if !c.state.Mounted {
return errors.Wrapf(ErrInternal, "container is not mounted")
@@ -1121,6 +1121,17 @@ func (c *Container) addImageVolumes(ctx context.Context, g *generate.Generator)
if err != nil {
return err
}
+ // Add the built-in volumes of the container passed in to --volumes-from
+ for _, vol := range c.config.LocalVolumes {
+ if imageData.ContainerConfig.Volumes == nil {
+ imageData.ContainerConfig.Volumes = map[string]struct{}{
+ vol: {},
+ }
+ } else {
+ imageData.ContainerConfig.Volumes[vol] = struct{}{}
+ }
+ }
+
for k := range imageData.ContainerConfig.Volumes {
mount := spec.Mount{
Destination: k,
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 0dc02d117..9ad825458 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -127,7 +127,7 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
// Bind builtin image volumes
if c.config.Rootfs == "" && c.config.ImageVolumes {
- if err := c.addImageVolumes(ctx, &g); err != nil {
+ if err := c.addLocalVolumes(ctx, &g); err != nil {
return nil, errors.Wrapf(err, "error mounting image volumes")
}
}
diff --git a/libpod/options.go b/libpod/options.go
index 9f07db7ed..c02bd4336 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -885,6 +885,24 @@ func WithUserVolumes(volumes []string) CtrCreateOption {
}
}
+// WithLocalVolumes sets the built-in volumes of the container retrieved
+// from a container passed in to the --volumes-from flag.
+// This stores the built-in volume information in the ContainerConfig so we can
+// add them when creating the container.
+func WithLocalVolumes(volumes []string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ if volumes != nil {
+ ctr.config.LocalVolumes = append(ctr.config.LocalVolumes, volumes...)
+ }
+
+ return nil
+ }
+}
+
// WithEntrypoint sets the entrypoint of the container.
// This is not used to change the container's spec, but will instead be used
// during commit to populate the entrypoint of the new image.