[yasuyuky/rust-nightly-musl](https://hub.docker.com/r/yasuyuky/rust-nightly-musl/dockerfile)イメージを使う。このイメージは[rustlang/rust:nightly](https://hub.docker.com/r/rustlang/rust/)をベースに以下の[[Dockerfile]]を実行しているだけ。 ```docker FROM rustlang/rust:nightly RUN apt-get -y update && apt-get -y install musl-tools RUN rustup target add x86_64-unknown-linux-musl ``` あとはビルド時にtargetを指定する。 ```shell cargo build --release --target x86_64-unknown-linux-musl ``` `target/x86_64-unknown-linux-musl/release`配下に成果物ができる。 ## runするとCargo.tomlが見つからないエラーが出る 以下のエラー ```console could not find `Cargo.toml` in `/` or any parent directory ``` なぜかworkdirが`root`になってしまっているため、`-w`オプションでworkdirを指定しておく。以下はaliasの一例。 ```shell alias rmb='docker run --rm -it -v "$(pwd)":/home/rust/src -w /home/rust/src yasuyuky/rust-nightly-musl' ``` 以下は実行例。 ```shell rmb cargo build --release --target x86_64-unknown-linux-musl ```