Skip to content

Commit 72be139

Browse files
authored
fix: container binds syntax (#2899)
The container binds syntax is `host-src:container-dest[:options]` or `volume-name:container-dest[:options]` where `options` is a comma separated list of: `nocopy` `[ro|rw]`, `[z|Z]` or `[[r]shared|[r]slave|[r]private]`. See `HostConfig.Binds` of the Create a container request[1] [1] https://docs.docker.com/reference/api/engine/version/v1.47/#tag/Container/operation/ContainerCreate
1 parent c28f0f8 commit 72be139

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (c *ContainerRequest) validateMounts() error {
532532
if len(hostConfig.Binds) > 0 {
533533
for _, bind := range hostConfig.Binds {
534534
parts := strings.Split(bind, ":")
535-
if len(parts) != 2 {
535+
if len(parts) != 2 && len(parts) != 3 {
536536
return fmt.Errorf("%w: %s", ErrInvalidBindMount, bind)
537537
}
538538
targetPath := parts[1]

container_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,33 @@ func Test_ContainerValidation(t *testing.T) {
7373
},
7474
{
7575
Name: "Invalid bind mount",
76-
ExpectedError: "invalid bind mount: /data:/data:/data",
76+
ExpectedError: "invalid bind mount: /data:/data:a:b",
7777
ContainerRequest: testcontainers.ContainerRequest{
7878
Image: "redis:latest",
7979
HostConfigModifier: func(hc *container.HostConfig) {
80-
hc.Binds = []string{"/data:/data:/data"}
80+
hc.Binds = []string{"/data:/data:a:b"}
81+
},
82+
},
83+
},
84+
{
85+
Name: "bind-options/provided",
86+
ContainerRequest: testcontainers.ContainerRequest{
87+
Image: "redis:latest",
88+
HostConfigModifier: func(hc *container.HostConfig) {
89+
hc.Binds = []string{
90+
"/a:/a:nocopy",
91+
"/b:/b:ro",
92+
"/c:/c:rw",
93+
"/d:/d:z",
94+
"/e:/e:Z",
95+
"/f:/f:shared",
96+
"/g:/g:rshared",
97+
"/h:/h:slave",
98+
"/i:/i:rslave",
99+
"/j:/j:private",
100+
"/k:/k:rprivate",
101+
"/l:/l:ro,z,shared",
102+
}
81103
},
82104
},
83105
},

0 commit comments

Comments
 (0)