Skip to content

Commit 8a4f2aa

Browse files
Use --mount on Windows
1 parent a848d94 commit 8a4f2aa

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/docker.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl DockerEnv {
5353
}
5454
}
5555

56-
#[derive(Copy, Clone)]
56+
#[derive(Copy, Clone, PartialEq, Eq)]
5757
pub(crate) enum MountPerms {
5858
ReadWrite,
5959
ReadOnly,
@@ -66,7 +66,7 @@ struct MountConfig {
6666
}
6767

6868
impl MountConfig {
69-
fn to_arg(&self) -> String {
69+
fn to_volume_arg(&self) -> String {
7070
let perm = match self.perm {
7171
MountPerms::ReadWrite => "rw",
7272
MountPerms::ReadOnly => "ro",
@@ -78,6 +78,21 @@ impl MountConfig {
7878
perm
7979
)
8080
}
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+
}
8196
}
8297

8398
pub(crate) struct ContainerBuilder<'a> {
@@ -147,8 +162,16 @@ impl<'a> ContainerBuilder<'a> {
147162

148163
for mount in &self.mounts {
149164
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+
}
152175
}
153176

154177
for &(ref var, ref value) in &self.env {

0 commit comments

Comments
 (0)