Skip to content

Commit 592e8e4

Browse files
committed
Fix named volumes
Signed-off-by: Josh Curl <[email protected]>
1 parent cd70e3a commit 592e8e4

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

Diff for: docker/convert.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ func ConvertToAPI(s *Service) (*ConfigWrapper, error) {
5555
return &result, nil
5656
}
5757

58+
func isNamedVolume(volume string) bool {
59+
return !strings.HasPrefix(volume, ".") && !strings.HasPrefix(volume, "/") && !strings.HasPrefix(volume, "~")
60+
}
61+
5862
func volumes(c *config.ServiceConfig, ctx project.Context) map[string]struct{} {
5963
volumes := make(map[string]struct{}, len(c.Volumes))
6064
for k, v := range c.Volumes {
61-
if len(ctx.ComposeFiles) > 0 {
65+
if len(ctx.ComposeFiles) > 0 && !isNamedVolume(v) {
6266
v = ctx.ResourceLookup.ResolvePath(v, ctx.ComposeFiles[0])
6367
}
6468

Diff for: integration/volume_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,22 @@ func (s *CliSuite) TestRelativeVolume(c *C) {
5656
c.Assert(cn, NotNil)
5757
c.Assert(len(cn.Mounts), DeepEquals, 1)
5858
c.Assert(cn.Mounts[0].Source, DeepEquals, absPath)
59+
c.Assert(cn.Mounts[0].Destination, DeepEquals, "/path")
60+
}
61+
62+
func (s *CliSuite) TestNamedVolume(c *C) {
63+
p := s.ProjectFromText(c, "up", `
64+
server:
65+
image: busybox
66+
volumes:
67+
- vol:/path
68+
`)
69+
70+
serverName := fmt.Sprintf("%s_%s_1", p, "server")
71+
cn := s.GetContainerByName(c, serverName)
72+
73+
c.Assert(cn, NotNil)
74+
c.Assert(len(cn.Mounts), DeepEquals, 1)
75+
c.Assert(cn.Mounts[0].Name, DeepEquals, "vol")
76+
c.Assert(cn.Mounts[0].Destination, DeepEquals, "/path")
5977
}

Diff for: lookup/file.go

-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ func (f *FileConfigLookup) ResolvePath(path, inFile string) string {
6161
if len(vs) != 2 || filepath.IsAbs(vs[0]) {
6262
return path
6363
}
64-
65-
if !strings.HasPrefix(vs[0], "./") && !strings.HasPrefix(vs[0], "~/") &&
66-
!strings.HasPrefix(vs[0], "/") {
67-
68-
logrus.Warnf("The mapping \"%s\" is ambiguous. In a future version of Docker, it will "+
69-
"designate a \"named\" volume (see https://github.com/docker/docker/pull/14242). "+
70-
"To prevent unexpected behaviour, change it to \"./%s\".", vs[0], vs[0])
71-
}
7264
vs[0] = relativePath(vs[0], inFile)
7365
return strings.Join(vs, ":")
7466
}

0 commit comments

Comments
 (0)