こんどは、Mozilla が開発に大きく携わったという、Rust にチャレンジ。
公式サイトによると、インストールは下記のスクリプト一発らしい。
curl https://sh.rustup.rs -sSf | sh
別にディストリビューションを限定するものでもないようだ。
ならば、Alpine でやってみようじゃないか。
が、Dockerfile 作ってビルドしようとすると、下記のようなエラーが出てダメ。
curl https://sh.rustup.rs -sSf info: downloading installer rustup: Unable to run interactively. Run with -y to accept defaults, --help for additional options
ならばと、素の Alpine のイメージからコンテナ作って、コンソールから順次コマンド実行していくと、今度は下記のようなエラーが出る。
info: downloading installer sh: /tmp/tmp.LEFggE/rustup-init: not found
おそらく、一時ファイルが上手く展開できていないのか。
Alpine Linux は軽量でいいのだが、やっぱり軽量な分特殊なのだろうか。
ということで、Docker Hub をあさってみると、オフィシャルのイメージがある。こいつは Debian ベースのようだ。
ならばと、Debian のlatestからコンテナ作って、進めてみる。
こちらは、curl を事前にインストールしとくくらいで、公式サイトのインストール手順で行けた模様。
# apt-get update # apt-get install curl # curl https://sh.rustup.rs -sSf | sh (中略) 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1 # source $HOME/.cargo/env # export USER=root # cargo new hello_world Created binary (application) `hello_world` package
この時点で、Hello world のソースも生成されているので、コンパイルしてみると、エラー。
# cargo build Compiling hello_world v0.1.0 (/home/rust/hello_world) error: linker `cc` not found | = note: No such file or directory (os error 2) error: aborting due to previous error error: Could not compile `hello_world`. To learn more, run the command again with --verbose.
よくよく、rust のオフィシャルイメージを見ると、Debian の素のパッケージを元にしてるわけではなく、「buildpack-deps:stretch」というものがベースになっている。
で、それをたどっていくと、下記のようにかなり遡らないと、Debian の素のイメージにたどり着かない。
- buildpack-deps:stretch
- buildpack-deps:stretch-scm
- buildpack-deps:stretch-curl
- debian:stretch
- buildpack-deps:stretch-curl
- buildpack-deps:stretch-scm
要は、rust は素の Debian に公式サイトのスクリプト一発で動かせるようなモノではなかったということか。
素のイメージからオフィシャルイメージに至るまでの間で、相当数のパッケージを導入しているが、Rust の公式を見てもどのパッケージが必須だという情報は出てこない。削れるものもあるかもしれないが、個別に精査していくにはホネが折れそうだ。
さすがに、オフィシャルイメージでコンテナ作って、それでHello worldがビルドできないということはなかったが、「export USER=root」はしてやらないとダメだった。(そうしないと、cargo new でエラーが起きる)