tyamaguc07's hatenablog

考えたり調べたりしたことを書いていく。

Rust開発環境 on Docker で Cargo new で "could not determine the current user, please set $USER" エラー

root@7e6ba33a449a:/projects# cargo new hogehoge
error: Failed to create project `hogehoge` at `/projects/hogehoge`

Caused by:
  could not determine the current user, please set $USER
root@7e6ba33a449a:/projects# ls -al
total 4
drwxr-xr-x 5 root root  160 Dec  2 05:22 .
drwxr-xr-x 1 root root 4096 Dec  2 05:21 ..
drwxr-xr-x 6 root root  192 Dec  2 04:58 helloworld
drwxr-xr-x 4 root root  128 Dec  2 05:22 hogehoge
drwxr-xr-x 6 root root  192 Dec  2 05:20 new_hello_world

エラーになる。(ディレクトリは作成される) メッセージの通り、現在のユーザが特定出来ないというもの。

解決方法はいくつかある。

  1. docker run 時に --env USER=ユーザ名 をつける
  2. DockerfileにENV USER=ユーザ名をつける

Rust Tutorialをやっていくにあたっては、2の手段が楽だと思ったので採用。