R-Car/Boards/Yocto-Gen3-CommonFAQ/How to build yocto image by using docker

From eLinux.org
< R-Car‎ | Boards/Yocto-Gen3-CommonFAQ
Revision as of 19:23, 18 February 2021 by Y.H. (talk | contribs) (How to build yocto image by using docker: Fix Dockerfile)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to build yocto image by using docker

Setup Docker image

Dockerfile(ubuntu 1804)

FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get dist-upgrade -y && apt-get autoremove --purge -y \
    && apt-get install -y \
       gawk wget git-core diffstat unzip texinfo gcc-multilib \
       build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
       xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \
       xterm locales curl vim sudo \
       rsync bc \
    && rm -rf /var/lib/apt/lists/* \
    && chmod 777 -R /home

# Locales
RUN dpkg-reconfigure locales \
    && locale-gen en_US.UTF-8 \
    && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LC_ALL   en_US.UTF-8
ENV LANG     en_US.UTF-8
ENV LANGUAGE en_US.UTF-8

Dockerfile(ubuntu:1604)

FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get dist-upgrade -y && apt-get autoremove --purge -y \
    && apt-get install -y \
       gawk wget git-core diffstat unzip texinfo gcc-multilib \
       build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
       xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \
       xterm locales curl vim sudo \
    && rm -rf /var/lib/apt/lists/* \
    && chmod 777 -R /home

# Locales
RUN dpkg-reconfigure locales \
    && locale-gen en_US.UTF-8 \
    && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LC_ALL   en_US.UTF-8
ENV LANG     en_US.UTF-8
ENV LANGUAGE en_US.UTF-8

docker build -t <image name> <path_to_Dockerfile>

ex.) docker build -t ubuntu:1804 ./

How to build

docker-run.sh

#!/bin/bash
WORK=`pwd`
DOCKER_IMG=$1; shift
cd ${HOME}
docker run -it --rm -u $(id -u):$(id -g) -v $(pwd):$(pwd) \
    -v /etc/group:/etc/group:ro  \
    -v /etc/passwd:/etc/passwd:ro \
    -v /etc/sudoers.d:/etc/sudoers.d:ro \
    -v /etc/shadow:/etc/shadow:ro \
    -w ${WORK} $DOCKER_IMG $*
cd ${WORK}

docker-run.sh <docker_image_name> <command>

ex.) docker-run.sh ubuntu:1804 ./build.sh h3ulcb

See also: