0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL2 Docker Yocto トラブルシューティング

0
Last updated at Posted at 2026-07-13

このページは、WSL2上にYocto BitBake用Docker環境を構築の構築、起動、BitBake実行時に発生する問題をまとめたものです。

最初に確認すること

  • compose.yamlがある~/yocto-docker-env/dockerで実行しているか
  • docker compose configUSER_UIDUSER_GIDが空でないか
  • 作業領域が/mnt/cではなくWSL2のext4上にあるか
  • Docker Desktop方式とWSL内Docker Engine方式を混在させていないか

T01. no configuration file provided: not found

症状

no configuration file provided: not found

原因

compose.yamlがないディレクトリでdocker composeを実行しています。

対策

cd ~/yocto-docker-env/docker
docker compose config

または明示します。

docker compose -f ~/yocto-docker-env/docker/compose.yaml config

T02. bash: UID: readonly variable

症状

bash: UID: readonly variable

原因

UIDはBash組み込みの読み取り専用変数です。

対策

USER_UID=$(id -u) \
USER_GID=$(id -g) \
USERNAME=yocto \
docker compose build

T03. docker-credential-desktop.exe: exec format error

症状

error getting credentials
fork/exec /mnt/c/Program Files/Docker/Docker/resources/bin/docker-credential-desktop.exe:
exec format error

原因

WSL内Docker CLIが、Windows版Docker Desktopのcredential helperを呼び出しています。

対策

確認:

cat ~/.docker/config.json
docker context ls

WSL内Docker Engineを使用する場合、バックアップ後にcredsStoreを削除します。

cp ~/.docker/config.json ~/.docker/config.json.bak

最小例:

{
  "auths": {}
}

確認:

docker pull ubuntu:24.04

Docker Desktopを使う場合は、WSL Integrationを有効化し、Windows実行ファイル連携を確認します。


T04. groupadd: option '--gid' requires an argument

症状

groupadd: option '--gid' requires an argument

原因

Dockerfileの${USER_GID}へ値が渡っていません。変数名がGROUP_IDUSER_GIDで不一致になっている場合もあります。

対策

Dockerfile、Compose、実行コマンドを次へ統一します。

USER_UID
USER_GID
USERNAME
USER_UID=$(id -u) \
USER_GID=$(id -g) \
USERNAME=yocto \
docker compose config

T05. useradd: UID 1000 is not unique

症状

useradd: UID 1000 is not unique

原因

Ubuntu 24.04ベースイメージには、最初からUID 1000のubuntuユーザーが存在します。

確認:

docker run --rm ubuntu:24.04 \
  sh -c 'getent passwd 1000; getent group 1000; getent group 1001'

確認結果例:

ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash
ubuntu:x:1000:

対策

UID 1000が既に存在する場合、useraddで新規作成せず、既存ユーザーをusermodyoctoへ変更します。

本ノートの完成版Dockerfileを使用してください。


T06. cannot create /etc/sudoers.d/yocto: Directory nonexistent

症状

/bin/sh: 1: cannot create /etc/sudoers.d/yocto: Directory nonexistent

原因

ユーザー作成処理が、sudoパッケージのインストールより先に実行されています。

対策

Dockerfileの順序を次にします。

1. apt-get install sudo
2. ユーザー・グループ作成または変更
3. /etc/sudoers.dへ設定
4. USER切り替え

念のため次も実行します。

mkdir -p /etc/sudoers.d

T07. Multiple CMD instructions should not be used

症状

MultipleInstructionsDisallowed: Multiple CMD instructions should not be used

原因

1つのDockerfileステージに複数のCMDがあります。Dockerでは最後のCMDだけが有効です。

対策

1つだけ残します。

CMD ["bash"]

T08. bitbake: command not found

症状

bash: bitbake: command not found

原因

Pokyのビルド環境を現在のシェルへ読み込んでいません。

対策

cd /work
source poky/oe-init-build-env build-qemu
which bitbake

/work/poky自体がない場合は、先にcloneします。

git clone -b scarthgap https://git.yoctoproject.org/poky

T09. /mnt/c上でBitBakeが遅い

症状

  • do_unpackdo_patchが遅い
  • CPU使用率が低い
  • Git操作や小ファイル処理が遅い

原因

NTFSとWSLの境界を跨ぐメタデータアクセスが多発しています。

対策

Yocto作業ディレクトリを/home/...配下へ置きます。

mkdir -p ~/yocto-docker-env

T10. bind mount先へ書き込めない

確認

id
ls -ldn /work /cache/downloads /cache/sstate-cache /artifacts

対策

WSL側のUID/GIDをビルド引数へ渡し、イメージを再ビルドします。

USER_UID=$(id -u) \
USER_GID=$(id -g) \
USERNAME=yocto \
docker compose build --no-cache

T11. Docker DesktopとWSL内Docker Engineが競合する

確認

docker context ls
which docker
ls -l /var/run/docker.sock

対策

使用するDockerを1つへ統一します。不要なcontext、credential helper、DOCKER_HOST設定を残さないようにします。


原因切り分け用コマンド

pwd
df -T .
id
cat ~/.docker/config.json
which docker
docker context ls
ls -l /var/run/docker.sock
docker pull ubuntu:24.04

cd ~/yocto-docker-env/docker
USER_UID=$(id -u) \
USER_GID=$(id -g) \
USERNAME=yocto \
docker compose config

関連ノート

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?