@@ -53,7 +53,7 @@ impl DockerEnv {
53
53
}
54
54
}
55
55
56
- #[ derive( Copy , Clone ) ]
56
+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
57
57
pub ( crate ) enum MountPerms {
58
58
ReadWrite ,
59
59
ReadOnly ,
@@ -66,7 +66,7 @@ struct MountConfig {
66
66
}
67
67
68
68
impl MountConfig {
69
- fn to_arg ( & self ) -> String {
69
+ fn to_volume_arg ( & self ) -> String {
70
70
let perm = match self . perm {
71
71
MountPerms :: ReadWrite => "rw" ,
72
72
MountPerms :: ReadOnly => "ro" ,
@@ -78,6 +78,21 @@ impl MountConfig {
78
78
perm
79
79
)
80
80
}
81
+
82
+ fn to_mount_arg ( & self ) -> String {
83
+ let mut opts_with_leading_comma = vec ! [ ] ;
84
+
85
+ if self . perm == MountPerms :: ReadOnly {
86
+ opts_with_leading_comma. push ( ",readonly" ) ;
87
+ }
88
+
89
+ format ! (
90
+ "type=bind,src={},dst={}{}" ,
91
+ absolute( & self . host_path) . to_string_lossy( ) ,
92
+ self . container_path. to_string_lossy( ) ,
93
+ opts_with_leading_comma. join( "" ) ,
94
+ )
95
+ }
81
96
}
82
97
83
98
pub ( crate ) struct ContainerBuilder < ' a > {
@@ -147,8 +162,16 @@ impl<'a> ContainerBuilder<'a> {
147
162
148
163
for mount in & self . mounts {
149
164
fs:: create_dir_all ( & mount. host_path ) ?;
150
- args. push ( "-v" . into ( ) ) ;
151
- args. push ( mount. to_arg ( ) )
165
+
166
+ // On Windows, we mount paths containing a colon which don't work with `-v`, but on
167
+ // Linux we need the Z flag, which doesn't work with `--mount`, for SELinux relabeling.
168
+ if cfg ! ( windows) {
169
+ args. push ( "--mount" . into ( ) ) ;
170
+ args. push ( mount. to_mount_arg ( ) )
171
+ } else {
172
+ args. push ( "-v" . into ( ) ) ;
173
+ args. push ( mount. to_volume_arg ( ) )
174
+ }
152
175
}
153
176
154
177
for & ( ref var, ref value) in & self . env {
0 commit comments