Skip to content

Commit 4c2ecb5

Browse files
ndeloofglours
authored andcommitted
reject compose file with bind mounts
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent bcd000a commit 4c2ecb5

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

pkg/compose/publish.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ func (s *composeService) preChecks(project *types.Project, options api.PublishOp
155155
}
156156
return acceptPublishEnvVariables(s.dockerCli)
157157
}
158+
159+
for name, config := range project.Services {
160+
for _, volume := range config.Volumes {
161+
if volume.Type == types.VolumeTypeBind {
162+
return false, fmt.Errorf("cannot publish compose file: service %q relies on bind-mount. You should use volumes", name)
163+
}
164+
}
165+
}
166+
158167
return true, nil
159168
}
160169

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
serviceA:
3+
image: a
4+
volumes:
5+
- .:/user-data

pkg/e2e/publish_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ FOO=bar`), res.Combined())
108108
assert.Assert(t, strings.Contains(res.Combined(), `QUIX=`), res.Combined())
109109
})
110110

111+
t.Run("refuse to publish with bind mount", func(t *testing.T) {
112+
res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/publish/compose-bind-mount.yml",
113+
"-p", projectName, "alpha", "publish", "test/test", "--dry-run")
114+
res.Assert(t, icmd.Expected{ExitCode: 1, Err: `cannot publish compose file: service "serviceA" relies on bind-mount. You should use volumes`})
115+
})
116+
111117
t.Run("refuse to publish with build section only", func(t *testing.T) {
112118
res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/publish/compose-build-only.yml",
113119
"-p", projectName, "alpha", "publish", "test/test", "--with-env", "-y", "--dry-run")

0 commit comments

Comments
 (0)