ubuntu x86环境创建armv8 ubuntu2004 64位docker服务器

在arm编译速度慢,运行vscode远程耗费资源,因此尝试在ubuntu服务器上搭建armv8 64位编译环境,过程很简单,记录如下

一、安装qemu解释器

bash 复制代码
# 宿主机安装解释器和时区设置
sudo apt install -y qemu-user-static tzdata
# 重启docker
sudo systemctl restart docker

二、编写Dockerfile

内容如下:

bash 复制代码
# 使用多阶段构建,首先从x86_64的Ubuntu镜像开始
FROM ubuntu:20.04 as builder

# 安装 qemu-user-static
RUN apt-get update && apt-get install -y qemu-user-static tzdata

# 设置时区为东八区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 从aarch64的Ubuntu镜像创建最终的镜像
FROM arm64v8/ubuntu:20.04

# 复制 qemu-aarch64-static 从x86_64镜像
COPY --from=builder /usr/bin/qemu-aarch64-static /usr/bin
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai

# 设置时区为东八区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo $TZ > /etc/timezone

# 替换源为清华镜像源
RUN sed -i s@/ports.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list
#    sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list && \
#    sed -i s@/security.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list

# 安装build-essential, cmake, Python及相关工具
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    vim \
    iputils-ping \
    net-tools \
    iproute2 \
    libssl-dev \
    libopencv-dev \
    libfreetype6-dev \
    libcurl4-openssl-dev \
    git \
    curl \
    wget \
    lsb-release \
    gdb \
    unzip \
    tar \
    python3 \
    python3-pip \
    python3-setuptools \
    python-is-python3 \
    software-properties-common \
    && rm -rf /var/lib/apt/lists/*

# 设置pip和pip3使用国内镜像源
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ pip -U && \
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ && \
    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ pip -U && \
    pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

# 设置工作目录
WORKDIR /workspace

# 指定默认命令
CMD ["/bin/bash"]

三、构建docker镜像

bash 复制代码
sudo docker build -t your_docker_image_name:your_tag -ubuntu2004 .

等待构建完成通过sudo docker images即可查看构建成功的镜像,也可通过docker save保存镜像

bash 复制代码
sudo docker save -o your_save_name.tar your_docker_image_name

通过docker run进入Docker

bash 复制代码
sudo docker run --network=host -v your_path:/workspace -it your_image_id /bin/bash
相关推荐
wangqiaowq8 小时前
windows下nginx的安装
linux·服务器·前端
cen__y9 小时前
Linux12(Git01)
linux·运维·服务器·c语言·开发语言·git
不仙52011 小时前
VMware Workstation 26.0.0 在 Ubuntu 24.04 (内核 6.17.0) 上的安装与内核模块编译问题
linux·ubuntu·elasticsearch
1892280486111 小时前
NY352固态MT29F32T08GWLBHD6-24QJ:B
大数据·服务器·人工智能·科技·缓存
AI视觉网奇11 小时前
linux 检索库 判断库是否支持
java·linux·服务器
dapeng-大鹏11 小时前
KVM+LVM 零停机在线扩容 Ubuntu 根分区:从磁盘添加到逻辑卷扩展完整
linux·运维·ubuntu·磁盘空间扩展
仙柒41512 小时前
Docker存储原理
运维·docker·容器
一楼的猫12 小时前
从工具链视角对比:番茄作家助手 vs 第三方写作辅助方案
java·服务器·开发语言·前端·学习·chatgpt·ai写作
武子康13 小时前
调查研究-138 全球机器人产业深度调研报告【01 篇】:市场规模、竞争格局与商业化成熟 2026
服务器·数据库·ai·chatgpt·机器人·具身智能
xhbh66613 小时前
代理ARP (Proxy ARP) 是如何实现跨网段通信的?在Linux下如何配置?
服务器·网络·智能路由器·端口映射·映射