1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Yocto ビルド用 Docker コンテナの構築方法

1
Posted at

Yocto ビルド用 Docker コンテナは、非 root ユーザーで BitBake を実行できるように作ります。git clonebitbakesudo が必要な構成は避けます。

推奨ディレクトリ

yocto-docker-env/
├─ docker/
│  ├─ Dockerfile.yocto-build
│  └─ docker-compose.yml
├─ workspace/
├─ cache/
│  ├─ downloads/
│  └─ sstate-cache/
└─ artifacts/

作成します。

mkdir -p yocto-docker-env/{docker,workspace,cache/downloads,cache/sstate-cache,artifacts}
cd yocto-docker-env

Dockerfile

docker/Dockerfile.yocto-build を作成します。

FROM ubuntu:22.04

ARG USERNAME=yocto
ARG USER_UID=1000
ARG USER_GID=1000

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
    gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat \
    cpio python3 python3-pip python3-pexpect python3-git python3-jinja2 \
    python3-subunit xz-utils debianutils iputils-ping file locales \
    libacl1 liblz4-tool zstd lz4 \
    sudo ca-certificates curl rsync bc bison flex \
    libssl-dev libelf-dev \
    vim nano less tree tmux \
    qemu-system-x86 qemu-system-arm qemu-system-aarch64 qemu-utils \
    && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
    && locale-gen en_US.UTF-8 \
    && update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 \
    && rm -rf /var/lib/apt/lists/*

ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

RUN groupadd --gid ${USER_GID} ${USERNAME} \
    && useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} \
    && echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} \
    && chmod 0440 /etc/sudoers.d/${USERNAME}

USER ${USERNAME}
WORKDIR /work

CMD ["/bin/bash"]

docker-compose.yml

docker/docker-compose.yml を作成します。

services:
  yocto-build:
    build:
      context: .
      dockerfile: Dockerfile.yocto-build
      args:
        USERNAME: yocto
        USER_UID: ${UID:-1000}
        USER_GID: ${GID:-1000}
    image: local/yocto-build:ubuntu22.04
    container_name: yocto-build
    hostname: yocto-build
    working_dir: /work
    tty: true
    stdin_open: true
    volumes:
      - ../workspace:/work
      - ../cache/downloads:/cache/downloads
      - ../cache/sstate-cache:/cache/sstate-cache
      - ../artifacts:/artifacts

QEMU の TUN/TAP ネットワークを使いたい場合は、追加で以下を足します。

    devices:
      - /dev/net/tun:/dev/net/tun
    cap_add:
      - NET_ADMIN

ただし、Docker 内の QEMU 確認だけなら runqemu ... slirp ... の方が簡単です。

ビルド

ホスト側で実行します。

cd yocto-docker-env/docker
UID=$(id -u) GID=$(id -g) docker compose build

起動

UID=$(id -u) GID=$(id -g) docker compose run --rm yocto-build

コンテナ内で確認します。

whoami
id
pwd
locale
locale -a | grep en_US

期待値です。

yocto
/work
en_US.utf8

権限確認

コンテナ内で以下が sudo なしで成功することを確認します。

touch /work/write-test
rm /work/write-test

失敗する場合は、ホスト側で所有者を戻します。

cd yocto-docker-env
sudo chown -R $(id -u):$(id -g) docker workspace cache artifacts
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?