From f3171e90cfa14863bf145b167a85ce0e0b522ddd Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 9 Sep 2021 09:14:13 +0200 Subject: [PATCH] prefix volumes with `container:` as we resolve service into container Signed-off-by: Nicolas De Loof --- pkg/compose/create.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/compose/create.go b/pkg/compose/create.go index f9beea418..60c319adf 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -353,6 +353,14 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project, } } + var volumesFrom []string + for _, v := range service.VolumesFrom { + if !strings.HasPrefix(v, "container:") { + return nil, nil, nil, fmt.Errorf("invalid volume_from: %s", v) + } + volumesFrom = append(volumesFrom, v[len("container:"):]) + } + hostConfig := container.HostConfig{ AutoRemove: autoRemove, Binds: binds, @@ -369,7 +377,7 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project, PortBindings: portBindings, Resources: resources, VolumeDriver: service.VolumeDriver, - VolumesFrom: service.VolumesFrom, + VolumesFrom: volumesFrom, DNS: service.DNS, DNSSearch: service.DNSSearch, DNSOptions: service.DNSOpts, @@ -612,7 +620,10 @@ func getVolumesFrom(project *types.Project, volumesFrom []string) ([]string, []s } firstContainer := getContainerName(project.Name, service, 1) - v := fmt.Sprintf("%s:%s", firstContainer, strings.Join(spec[1:], ":")) + v := fmt.Sprintf("container:%s", firstContainer) + if len(spec) > 2 { + v = fmt.Sprintf("container:%s:%s", firstContainer, strings.Join(spec[1:], ":")) + } volumes = append(volumes, v) } return volumes, services, nil