Skip to content

Docker-in-Docker fails with Mounted Volumes in Workspaces #901

@Alexhuszagh

Description

@Alexhuszagh

Checklist

Describe your issue

When running docker-in-docker, if using a workspace and not at the root directory, the mounted volumes in the workspace are not properly adjusted to the the mounted prefix. This is because docker_mount does not use the mount finder.

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.2 (00c1de2)

Example

While testing the integration tests in #873, the following script fails, producing the subsequent output:

Script

#!/usr/bin/env bash

# test to see that running docker-in-docker works

set -x
set -eo pipefail

if [[ -z "${TARGET}" ]]; then
    export TARGET="aarch64-unknown-linux-gnu"
fi

source=$(dirname "${BASH_SOURCE[0]}")
source=$(realpath "${source}")
home=$(dirname "${source}")

main() {
    docker run -v "${home}":/project \
        -w /project --rm -e TARGET \
        -v /var/run/docker.sock:/var/run/docker.sock \
        docker:18.09-dind sh -c '
#!/usr/bin/env sh
set -x
set -euo pipefail

apk add curl
curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "${HOME}/.cargo/env"

# building on release is slow
apk add libgcc gcc musl-dev
cargo test --workspace
cargo install --path . --force --debug

export CROSS_CONTAINER_IN_CONTAINER=1

apk add git
td="$(mktemp -d)"
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
cd "${td}"
cross run --target "${TARGET}" --verbose

td="$(mktemp -d)"
git clone --depth 1 https://github.com/cross-rs/test-workspace "${td}"
cd "${td}"
cross build --target "${TARGET}" --workspace \
    --manifest-path="./workspace/Cargo.toml" --verbose
cd workspace
cross build --target "${TARGET}" --workspace --verbose
cd binary
cross run --target "${TARGET}" --verbose
'
}

main

Output

/usr/local/bin/docker run --userns host -e 'PKG_CONFIG_ALLOW_CROSS=1' -e 'XARGO_HOME=/xargo' -e 'CARGO_HOME=/cargo' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e 'USER=root' -v /tmp/tmp.hppfjI/external/external_lib:/tmp/tmp.hppfjI/external/external_lib --rm --user 0:0 -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/root/.xargo:/xargo:Z -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/root/.cargo:/cargo:Z -v /cargo/bin -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace:/var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace:Z -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu:/rust:Z,ro -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace/target:/target:Z -w /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace ghcr.io/cross-rs/aarch64-unknown-linux-gnu:0.2.2 sh -c 'PATH=$PATH:/rust/bin cargo build --target aarch64-unknown-linux-gnu --workspace --verbose'
error: failed to load manifest for workspace member `/var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace/binary`

Caused by:
  failed to load manifest for dependency `test-workspace`

Caused by:
  failed to load manifest for dependency `external_lib`

Caused by:
  failed to read `/var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/external/external_lib/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

We can see that external_lib is mounted at /tmp/tmp.hppfjI/external/external_lib:/tmp/tmp.hppfjI/external/external_lib , and not at /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/test-workspace/external/external_lib/. Likewise, we only mount workspace, and not test-workspace.

Additional information / notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions