苗火 Nicholas
Docker images for petalinux
2025-11-10 萧


Dockerfile: 










# 使用 Ubuntu 20.04 作为基础镜像
FROM ubuntu:20.04

# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
ENV PETALINUX_INSTALLER=petalinux-v2021.2-final-installer.run
ENV PETALINUX_DIR=/data/working/peta

# 重新生成 sources.list 文件
RUN dpkg --add-architecture i386 && \
cat > /etc/apt/sources.list << 'EOF'
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
EOF


# 更新并安装基础工具
RUN apt update && apt install -y \
sudo wget curl gnupg lsb-release software-properties-common \
locales tzdata

# 设置时区和 locale
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8

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


# 安装所有依赖(包括32位)
RUN apt install -y \
# 64位依赖
bc rsync file \
python3 python3-pip build-essential \
tofrodos iproute2 gawk xvfb git make net-tools \
libncurses5-dev tftpd zlib1g-dev libssl-dev flex bison \
libselinux1 gnupg wget diffstat chrpath socat xterm \
autoconf libtool tar unzip texinfo gcc-multilib g++-multilib \
libsdl1.2-dev libglib2.0-dev screen pax gzip cpio \
# 32位库
zlib1g:i386 libstdc++6:i386 libc6:i386 lib32z1 lib32stdc++6 \
tofrodos gawk xvfb git libncurses5-dev tftpd zlib1g-dev zlib1g-dev:i386 \
libssl-dev flex bison chrpath socat autoconf texinfo gcc-multilib libsdl1.2-dev libglib2.0-dev \
screen pax bc gperf texi2html help2man libtool build-essential automake \
device-tree-compiler qemu-user-static binfmt-support multistrap lib32z1 libncurses6:i386 \
libbz2-1.0 lib32stdc++6 libgnutls28-dev kpartx zerofree u-boot-tools rpm2cpio \
libtinfo5 vim \
&& apt clean && rm -rf /var/lib/apt/lists/*

# 创建 petalinux 用户
RUN useradd -m -s /bin/bash petalinux && \
echo 'petalinux:petalinux' | chpasswd && \
echo 'petalinux ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# 设置工作目录
WORKDIR /data/working/peta
VOLUME /data/working/

# 设置环境变量
RUN echo "source ${PETALINUX_DIR}/settings.sh" >> /home/petalinux/.bashrc && \
echo "export PATH=\${PATH}:${PETALINUX_DIR}/tools/xsct/bin" >> /home/petalinux/.bashrc

# 修复权限
RUN chown -R petalinux:petalinux /home/petalinux

# 设置入口点
CMD ["/bin/bash"]






Create images:



docker build -t peta2021 .







Run images:



docker run -it \
--name petalinux-dev \
--hostname petalinux-dev \
--privileged \
--memory=8g \
--cpus=4 \
-v /data/working:/data/working \
-v /opt/sstate-cache:/opt/sstate-cache \
-v /opt/downloads:/opt/downloads \
peta2021





发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容