Skip to content

Commit e7dc70a

Browse files
committed
Bug fixes for podman and docker on Windows native.
1 parent 9573124 commit e7dc70a

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/docker.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ const SECCOMP: &str = include_str!("seccomp.json");
2424

2525
// determine if the container engine is docker. this fixes issues with
2626
// any aliases (#530), and doesn't fail if an executable suffix exists.
27-
fn get_is_docker(ce: std::path::PathBuf, verbose: bool) -> Result<bool> {
27+
fn get_engine_type(ce: std::path::PathBuf, verbose: bool) -> Result<(bool, bool)> {
2828
let stdout = Command::new(ce)
2929
.arg("--help")
3030
.run_and_get_stdout(verbose)?
3131
.to_lowercase();
3232

33-
Ok(stdout.contains("docker") && !stdout.contains("emulate"))
33+
let is_docker = stdout.contains("docker") && !stdout.contains("emulate");
34+
let is_podman = stdout.contains("podman");
35+
Ok((is_docker, is_podman))
3436
}
3537

3638
fn get_container_engine() -> Result<std::path::PathBuf, which::Error> {
@@ -144,7 +146,8 @@ pub fn run(
144146
let runner = config.runner(target)?;
145147

146148
let mut docker = docker_command("run")?;
147-
let is_docker = get_is_docker(get_container_engine().unwrap(), verbose)?;
149+
#[allow(unused_variables)] // is_podman, target_os = "windows"
150+
let (is_docker, is_podman) = get_engine_type(get_container_engine().unwrap(), verbose)?;
148151

149152
for ref var in config.env_passthrough(target)? {
150153
validate_env_var(var)?;
@@ -195,18 +198,31 @@ pub fn run(
195198

196199
// docker uses seccomp now on all installations
197200
if target.needs_docker_seccomp() {
198-
let path = env::current_dir()
199-
.wrap_err("couldn't get current directory")?
200-
.canonicalize()
201-
.wrap_err_with(|| "when canonicalizing current_dir".to_string())?
202-
.join("target")
203-
.join(target.triple())
204-
.join("seccomp.json");
205-
if !path.exists() {
206-
write_file(&path, false)?.write_all(SECCOMP.as_bytes())?;
207-
}
201+
let seccomp = if is_docker && cfg!(target_os = "windows") {
202+
// docker on windows fails due to a bug in reading the profile
203+
// https://github.com/docker/for-win/issues/12760
204+
"unconfined".to_string()
205+
} else {
206+
#[allow(unused_mut)] // target_os = "windows"
207+
let mut path = env::current_dir()
208+
.wrap_err("couldn't get current directory")?
209+
.canonicalize()
210+
.wrap_err_with(|| "when canonicalizing current_dir".to_string())?
211+
.join("target")
212+
.join(target.triple())
213+
.join("seccomp.json");
214+
if !path.exists() {
215+
write_file(&path, false)?.write_all(SECCOMP.as_bytes())?;
216+
}
217+
#[cfg(target_os = "windows")]
218+
if is_podman {
219+
// podman weirdly expects a WSL path here, and fails otherwise
220+
path = wslpath(&path, verbose)?;
221+
}
222+
path.display().to_string()
223+
};
208224

209-
docker.args(&["--security-opt", &format!("seccomp={}", path.display())]);
225+
docker.args(&["--security-opt", &format!("seccomp={}", seccomp)]);
210226
}
211227

212228
// We need to specify the user for Docker, but not for Podman.

0 commit comments

Comments
 (0)