Matjaz Zibert
Created May 7, 2025 © GPL3+

Project-1: Run PetaLinux in Docker: Isolated Development

Quickly spin up PetaLinux inside Docker for a reproducible, portable Kria development setup without polluting your host system.

ExpertFull instructions provided2 hours71
Project-1: Run PetaLinux in Docker: Isolated Development

Things used in this project

Hardware components

AMD Kria™ KR260 Robotics Starter Kit
AMD Kria™ KR260 Robotics Starter Kit
×1

Software apps and online services

PetaLinux
AMD PetaLinux
Docker Engine

Story

Read more

Code

Dockerfile

Dockerfile
PetaLinux Development Environment for Kria Boards
Ubuntu 22.04 base image with all required dependencies and TFTP setup
# --------------------------------------------------------------------
# Dockerfile: PetaLinux Development Environment for Kria Boards
# Ubuntu 22.04 base image with all required dependencies and TFTP setup
# --------------------------------------------------------------------

# Base image: Official Ubuntu 22.04 LTS
FROM ubuntu:22.04

# Set APT to non-interactive to avoid prompts during package installs
ENV DEBIAN_FRONTEND=noninteractive

# Install all necessary development tools and dependencies for PetaLinux
RUN apt update && apt install -y \
    sudo \
    vim \
    wget \
    curl \
    net-tools \
    iputils-ping \
    locales \
    tzdata \
    git \
    libtool \
    texinfo \
    zlib1g-dev \
    gcc-multilib \
    build-essential \
    tofrodos \
    gawk \
    chrpath \
    diffstat \
    unzip \
    sysvinit-utils \
    xterm \
    python3 \
    python3-pip \
    xz-utils \
    cpio \
    libncurses5-dev \
    libncursesw5-dev \
    libssl-dev \
    libelf-dev \
    libtinfo5 \
    device-tree-compiler \
    bc \
    rsync \
    file \
    dnsutils \
    dialog \
    screen \
    tmux \
    lsb-release \
    binwalk \
    bsdmainutils \
    bash-completion \
    tftpd-hpa  # lightweight TFTP server for U-Boot netboot

# Install specific GCC version (optional, adjust as needed)
RUN apt install -y gcc-10 g++-10 && \
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100

# Set up locale to avoid potential build script issues
RUN locale-gen en_US.UTF-8

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

# Optional: Target Kria board IP for scripts (can override at runtime)
ENV TARGET=192.168.1.26

# Arguments to create a user that maps to host user (recommended with volume mounts)
ARG USERNAME=kria
ARG USER_UID=1001
ARG USER_GID=1000

# Create non-root user with sudo privileges
RUN groupadd -g ${USER_GID} ${USERNAME} && \
    useradd -m -u ${USER_UID} -g ${USER_GID} -s /bin/bash ${USERNAME} && \
    echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Make bash the default shell (some tools/scripts require this)
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Set up symbolic link to expected TFTP directory
ARG TFTPDIR=/home/${USERNAME}/workspace/tftpboot
RUN ln -s ${TFTPDIR} /tftpboot

# Auto-start TFTP server and source PetaLinux tools on container start
RUN echo "service tftpd-hpa restart > /dev/null" >> /home/${USERNAME}/.bashrc && \
    echo "source /tools/petaLinux/2024.2/settings.sh" >> /home/${USERNAME}/.bashrc

# Switch to non-root user for development
USER ${USERNAME}
WORKDIR /home/${USERNAME}/workspace

# Set default umask so shared files are writable by group (useful with host volumes)
RUN echo "umask 0002" >> /home/${USERNAME}/.bashrc

# Optional: pre-configure Git (or let user do it later)
RUN git config --global user.name "Your Name" && \
    git config --global user.email "you@example.com"

# Default command when container starts
CMD ["/bin/bash"]

build.sh

SH
This script builds the Docker image for PetaLinux 2024.2 development using the provided Dockerfile. It ensures the user inside the container matches your host user’s group for proper file permissions.
#!/bin/bash
# Build the Docker image for Kria PetaLinux development
# Ensures group ID matches host user to avoid file permission issues with volumes

docker build \
  --build-arg USER_GID=$(id -g) \
  -t petalinux-2024.2:kria \
  -f Dockerfile .

run.sh

SH
This script runs the container with device and tool access, shared volumes for source/app files, and ensures the container can access the host’s /dev and PetaLinux tools. Adjust volume paths as needed.
#!/bin/bash
# Launch the PetaLinux development container for Kria boards

# shared directories description
#  /dev             # Pass through host devices
#  /tools           # Mount directory where PetaLinux is installed
#  $(pwd)/workspace # Shared workspace folder

docker run --rm -it \
  --privileged \
  -v /dev:/dev \
  -v /tools:/tools \
  -v $(pwd)/workspace:/home/kria/workspace \
  --name kria-cross-dev \
  petalinux-2024.2:kria

Credits

Matjaz Zibert
14 projects • 31 followers
Hardware Engineer with Software Development Skills, Extensive background in telecommunications, FPGA integration, Callsign S59MZ (Ham-Radio)

Comments