Description
Continuation of #260 (comment) and #260 (comment).
Description of the problem
Running cross
from a Docker container (e.g. Docker in Docker) that runs in WSL does not work, it seems like the root cause is how Docker and volumes are created and mounted in WSL but this is so far just a guess.
Running with CROSS_DOCKER_IN_DOCKER=true
(which I should have to) will discover a volume path that is not mounted in the current container.
Runing with CROSS_DOCKER_IN_DOCKER=false
won't work because mounting a directory from a Docker container to another does not work afaik.
Setup
- Windows 11
- WSL2
- Ubuntu 20.04
- Rancher Desktop 1.3.0
cross
0.2.1cargo
1.61.0
How to reproduce
Start build container that includes Docker
docker run --rm -it --entrypoint bash \
-e CROSS_DOCKER_IN_DOCKER=true \
-v /var/run/docker.sock:/var/run/docker.sock \
gcr.io/cloud-builders/docker
Install Rust and cross
, create project
apt update && apt install build-essential -y
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
source $HOME/.cargo/env
cargo install cross
cargo init hello-world && cd hello-world
Try to build with cross
cross build
info: downloading component 'rust-src'
info: installing component 'rust-src'
sh: 1: cargo: not found
Quicker repro without cross
Start DinD container and create file
docker run --rm -it --entrypoint /bin/sh -v /var/run/docker.sock:/var/run/docker.sock docker:latest
apk add --update jq
mkdir test
echo "Hello, World" > test/file.md
Mount the MergedDir
directory
This will work on macOS and Linux but not WSL.
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(docker inspect $HOSTNAME | jq -r .[0].GraphDriver.Data.MergedDir)/test:/workdir \
docker:latest cat /workdir/file.md
Troubleshooting root cause
Show more
UPDATE: This seems to be incorrect and irrelevant
I'm not very familiar with WSL and Docker but I noticed that if I start the container like in the first step from WSL, install jq
and look at the same path as what the code found here does, I get:
docker inspect $HOSTNAME | jq -r .[0].GraphDriver.Data.MergedDir
/var/lib/docker/overlay2/7c8b6ec02033086d5f6de2b10b984991d92bddd2c58e893216dfef6a67a0ce3a/merged
stat /var/lib/docker
stat: cannot stat '/var/lib/docker': No such file or directory
I guess this is not expected since the output from cross build -v
refers to this directory for the whole toolchain:
CROSS_DOCKER_IN_DOCKER=true cross build -v
+ "rustc" "--print" "sysroot"
+ "rustup" "toolchain" "list"
+ "rustup" "target" "list" "--toolchain" "stable-x86_64-unknown-linux-gnu"
+ "rustup" "component" "list" "--toolchain" "stable-x86_64-unknown-linux-gnu"
+ "/usr/bin/docker" "run" "--userns" "host" "-e" "PKG_CONFIG_ALLOW_CROSS=1" "--rm" "--user" "0:0" "-e" "XARGO_HOME=/xargo" "-e" "CARGO_HOME=/cargo" "-e" "CARGO_TARGET_DIR=/target" "-e" "USER=root" "-e" "CROSS_RUNNER=" "-v" "/var/lib/docker/overlay2/7c8b6ec02033086d5f6de2b10b984991d92bddd2c58e893216dfef6a67a0ce3a/merged/root/.xargo:/xargo:Z" "-v" "/var/lib/docker/overlay2/7c8b6ec02033086d5f6de2b10b984991d92bddd2c58e893216dfef6a67a0ce3a/merged/root/.cargo:/cargo:Z" "-v" "/cargo/bin" "-v" "/var/lib/docker/overlay2/7c8b6ec02033086d5f6de2b10b984991d92bddd2c58e893216dfef6a67a0ce3a/merged/hello-world:/project:Z" "-v" "/var/lib/docker/overlay2/7c8b6ec02033086d5f6de2b10b984991d92bddd2c58e893216dfef6a67a0ce3a/merged/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu:/rust:Z,ro" "-v" "/var/lib/docker/overlay2/7c8b6ec02033086d5f6de2b10b984991d92bddd2c58e893216dfef6a67a0ce3a/merged/hello-world/target:/target:Z" "-w" "/project" "-i" "-t" "rustembedded/cross:x86_64-unknown-linux-gnu-0.2.1" "sh" "-c" "PATH=$PATH:/rust/bin cargo build -v"
sh: 1: cargo: not found
I would guess this has to do with how Docker Desktop and Rancher Desktop sets up data volumes separate from each other and separate from WSL:
wsl --list -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
rancher-desktop Running 2
rancher-desktop-data Running 2