Ubuntu安装docker buildx打包全平台镜像sub-web镜像

VM安装Ubuntu

  1. 获取Ubuntu服务器版 | Ubuntu下载Server版本,版本架构随便自己选,一般应该是amd64的。

  2. 新建虚拟机

    • 新建虚拟机我们可以从【左侧侧边栏】鼠标右键,选择 【新建虚拟机(N)】也可以在右侧 主页,点击 【创建新的虚拟机】
    • 选择 【自定义(高级)(C)】,然后点击 【下一步】
    • 选择虚拟机硬件兼容性,这一项尽量选高版本,我的是vm16.2,所以选择的【硬件兼容性(H)】:Workstation 16.2.x,然后【下一步】
    • 安装客户机操作系统,选择【稍后安装操作系统(S)】,选择【下一步】
    • 选择客户机操作系统,选中【Linux(L)】,版本(v)选择:【Ubuntu 64位】,【下一步】
    • 命名虚拟机,随便填写一个你喜欢的【虚拟机名称(V)】:Ubuntu 64位;选择好虚拟机要存放的位置,【位置(L):】,【下一步】
    • 处理器配置,这一项根据自己的电脑配置随意,【处理器数量(P):2】,【每个处理器的内核数量(C):1】,【下一步】
    • 此虚拟机的内存,这个一般不小于4G,【下一步】
    • 网络类型,我一般都是选择的【使用桥接网络(R)】,和电脑在同一段IP地址内。【下一步】
    • 迭择I/O控制器类型,【LSI Logic(L)(推荐)】,【下一步】
    • 迭择磁盘类型,【SCSI(S)(推荐)】,【下一步】
    • 迭择磁盘,一般是【创建新虚拟磁盘(V)】,如果你已经有一个虚拟磁盘了,就选【使用现有虚拟磁盘(E)】,【下一步】
    • 指定磁盘容量,【最大磁盘大小(GB)(S):20.0】,【将虚拟磁盘存储为单个文件(0)】,【下一步】
    • 指定磁盘文件,这个是要你指定刚创建的虚拟磁盘存放的位置,最好是前面目录的同一路径下,【这里不要动,不动就是同一路径下】,【下一步】
    • 已准备好创建虚拟机,可以点【自定义硬件(C)】查看你虚拟机的配置,也可以直接点【完成】
  3. 安装Ubuntu系统温馨提示:安装操作系统的过程中如果想从虚拟机切换到正常桌面可以按Ctrl+Alt

    • 先选中我们刚刚创建的虚拟机,然后点击 【编辑虚拟机设置】

    • 虚拟机设置,选中【硬件】中的【CD/DVD(SATA) 自动检测】,在右边【设备状态】中选中【启动时连接】,【连接】中选中【使用ISO映像文件】,点击【浏览】,载入你上面下载的ubuntu-24.04.3-live-server-amd64.iso系统,点击【确定】

    • 选中我们刚刚创建的虚拟机,然后点击 【开启此虚拟机】

    • 开机后出现的三个选项中:选中第一个:【Try or Install Ubuntu Server】,【回车】

      Try or Install Ubuntu Server
      Ubuntu Server with the HUE kernel
      Test MeMory
    • 等待出现:【Use UF. DONN and ENTER keys to select your language】,这个界面是让选择语言,但是没有中文,这里暂时只能先选择 【English】了,选好以后按下 【回车】键,(后续可以通过安装中文包支持中文,继续往下看吧,下面有设置中文的教程。

      Use UF. DONN and ENTER keys to select your language 
      [] Asturianu
      []Bahasa Indonesia
      []Catala []Deutsch
      []English
      []English (UK)
      []Espano1
      ...........
    • Please select your keyboard layout below, or select “Identify keyboard”to detect your layout automatically,这个界面是 【键盘配置】 ,没有中文选项,直接 【English】 ,然后选择下方的 【Done】 (完成)按下 【回车键】

      Layout: [ English (US)]
      Variant:[ English (US)]
      [ Identify keyboard ]
      [Done]
      [Back]
    • Choose the base for the installation,这个界面是 【选择安装类型】,我们直接默认正常安装就行了,然后选择下方的 【Done】 (完成)按下 【回车键】(如有你有其他需求,请自行选择,方向键上下移动,空格键选中

      (X) Ubuntu Server #这是安装标准 Server版本
      ( ) Ubuntu Server (minimized) # 这是安装迷你版本
      Additional options
      [ ] Search for third-party drivers # 搜索一些第三方驱动什么的
      [Done]
      [Back]
    • 这个界面是 【网络连接配置】,如果你一开始跟我一起选择了桥接模式,这里就不需要管,选择下方的【Done】(完成)按下 【回车键】:
      Configure at least one interface this server can use to talk to other machines, and which preferably provides sufficient access for updates 
      NAME   TYPE NOTES
      [ens33  eth   -  ]
      ....# 这是是显示连接上的ip地址
      (Copper)
      [ Create bond  ]
      

      - 这个界面是 【配置代理】,直接选择下方的 【Done】 (完成)按下 【回车键】

      ```bash
      If this system requires a proxy to connect to the internet, enter its details here.
      Proxy address: [ ]
      If you need to use a HTP proxy to access the outside world, enter the proxy information here. Otherwise leave this blank. The proxy information should be given in the standard form of "http:7/[[ user] [: pass]0lhost [: port]/".
    • 这是镜像地址测试。直接【Done】,【回车】

      If you use an alternative mirror for Ubuntu, enter its details here. 
      Mirror address: http://cn. archive. ubuntu. com/ubuntu/
      You may provide an archive mirror to be used instead of the default This mirror location passed tests.
      Hit:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
      Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease [126 kB]
      Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease [126kB] Fetched 252 kB in 2s (107 kB/S)
      Reading package lists
    • 这个界面是 【引导存储配置】 ,这里可以进行一些分区操作等。一般没需求就直接默认就行了,然后选择下方的 【Done】 (完成)按下 【回车键】

      Configure a guided storage layout, or create a custom one: 
      (x) Use an entire disk
      [ /dev/sda local disk 20.000G -]
      (x)Set up this disk as an LVM group
      [] Encrypt the LVM group with LUKS
      ( )Custom storage layout
    • 这个界面是 【分配的存储配置】,如果不满意可以在这里修改,如果修改坏了可以选择下面的 【Reset】 进行重置。一般不需要修改,直接选择下方的 【Done】 (完成)按下 【回车键】

      FILE SYSTEM SUMMARY 
      [/dev/sda local disk 20.000G
      partition 1 new, BIOS grub spacer 1.000M
      partition 2 new, to be formatted as ext4, mounted at /boot 1.771G
      partition 3 new, PV of LVM volume group ubuntu-vg 18.225G
    • 这里是提示我们要不要继续,如果继续会格式化磁盘(我们一开始分配的虚拟磁盘,不是真正的磁盘,别怕)然后还提醒我们如果继续就回不到上一步了。我们直接选择 【Continue】,【 回车】即可

             Confirm destructive action 
      Selecting Continue below will begin the installation process and result in the loss of data on the disks selected to be formatted.
      You will not be able to return to this or a previous screen once the installation has started
      Are you sure you want to continue?
      [No]
      [Continue]
    • 这个界面是让我们创建一个普通用户,这里跟桌面版的Ubuntu一样的。
      第一个是你的姓名。(这个可以不填)
      第二个是你的计算机名(与其他计算机联络时使用的名称。比如 root@study02-ubuntu-server:~$)。
      第三个是用户名,就是这个普通用户的登录账号。
      第四个是这个用户的密码。
      第五个是确认这个用户的密码。也就是再输入一次。
      填写完成后选择下方的 【Done【 (完成)按下【 回车键】

      Enter the username and password you will use to log in to the system. You can configure SSH access on a later screen, but a password is still needed for sudo. Your name: 
      Your servers name:
      Pick a username:
      Choose a password:
      Confirm your password:
    • 这个界面是问你要不要升级 【Ubuntu Pro】,对不起,没钱!!!直接选择下方的 【Continue】 (完成)按下 【回车键】

      Upgrade this machine to Ubuntu Pro for security updates on a much wider range of packages, until 2034. Assists with FedRAMP FIPS, STIG, HIPAA and other compliance or hardening requirements
      [ About Ubuntu Pro c]
      ( ) Enable Ubuntu Pro
      (X) skin for now
      You can always enable Ubuntu Pro later using the ' pro attach' command.
    • 这个界面是要 安装SSH,安装了后面通过SSH工具连接Ubuntu Server。我们是需要的,所以光标选择到 Install OpenSSH server 按一下回车,当前面的 [ ],变成 [ x ] 以后,选择下方的 Done (完成)按下 回车键

      You can choose to install the OpenSSH server package to enable secure remote access to your server
      [x] Install OpenSSH server
      [X] Allow password authentication over SSH
      [ Import SSH key ]
      AUTHORIZED KEYS
      No authorized key
    • 这个界面是问你要不要加载一些加工好的快照,比如什么内置了普罗米修斯的等等。我这里只是做测试用,我不需要加载别人的快照。直接选择下方的 Done (完成)按下 回车键

      These are popular snaps in server environments. Select or deselect with SPACE, press ENTER to see more details of the package, publisher and versions available. [] microk8s canonicaly Kubernetes for workstations and appliances 
      [] nextcloud nextcloudv Nextcloud Server -A safe home for all your data
      [] wekan xet7 Open-Source kanban
      []canonical-livepatch canonicalv Canonical Livepatch Client
      .............
    • 下面就等待安装完成

    • 当底下出现有【Reboot Now】时,选中【Reboot Now】,【回车】,就会重新启动。

    • 当出现如下错误时:请关闭虚拟机,移除前面加载的ubuntu-24.04.3-live-server-amd64.iso后,再重新启动虚拟机。如果不移除,也可以直接在这个界面上【回车】重启

      (FAILEDI Failed unmounting cdrom. mount -/cdrom. 
      Please remove the installation medium, then press ENTER:
      [ FAILED] Failed unmounting cdrom. mount -/cdrom.
    • 这就安装完成了。

  4. 在安装的过程中,有的也可能出现,这个界面是告诉你,系统有更新了,问你要不要更新一下。这里我们先直接选择 Continue without updating ,不更新继续,不然后要等很长时间,然后按下 回车键

    Installer update available
    Version 24.04.1 of the installer is now available(24.02.1 is currently running).
    You can read the release notes for each version at:
    https://github.com/canonical/subiquity/releases
    If you choose to update,the update will be downloaded and the installation will continue from here.
    [Update to the new install] # 更新到新的安装程序
    [Continue without updating] # 不更新,继续
    [Back] #返回上一级

ubuntu操作

  1. 启动虚拟机,输入我们刚刚创建的 ubuntu 用户,即可登录,输入 ip addr show 查看ip地址,以ssh连接。

  2. 使用远程工具MobaXterm上登录,

    # 输入用户名
    login as: xxx
    # 输入上面设置的密码,密码不显示,密码输完回车就可以了
    xxx@192.168.50.23's password:
  3. 开户root用户登录:

    # 输入修改root密码的命令:sudo passwd root
    xxx@ubuntu:~$ sudo passwd root
    # 输入设置的用户名的密码 回车
    [sudo] password for xxx:
    # 设置 root 的密码,不显示
    New password:
    # 再输一次
    Retype new password:
    # 提示成功
    passwd: password updated successfully
    xxx@ubuntu:~$
  4. 传统方式切换root用户,缺点:只能当前终端窗口有效。每次打开新的终端窗口都需要进行命令切换。

    # 输入:su root
    xxx@ubuntu:~$ su root
    # 输入root 密码
    Password:
    root@ubuntu:/home/xxx#
  5. 直接用root用户登录:在登录时,可以直接输入root账号密码登录:

    root@ubuntu:/home/xxx# nano /etc/ssh/sshd_config
    # 在打开的 sshd_config文件中,光标移动到时PermitRootLogin prohibit-password,回车,在下一行输入
    # 'PermitRootLogin yes',如下:
    GNU nano 7.2 /etc/ssh/sshd_config

    # This is the sshd server system-wide configuration file. See
    ......

    Include /etc/ssh/sshd_config.d/*.conf

    # When systemd socket activation is used (the default), the socket
    # configuration must be re-generated after changing Port, AddressFamily, or
    # ListenAddress.
    #
    # For changes to take effect, run:
    #
    # systemctl daemon-reload
    # systemctl restart ssh.socket
    #
    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::

    #HostKey /etc/ssh/ssh_host_rsa_key
    #HostKey /etc/ssh/ssh_host_ecdsa_key
    #HostKey /etc/ssh/ssh_host_ed25519_key

    # Ciphers and keying
    #RekeyLimit default none

    # Logging
    #SyslogFacility AUTH
    #LogLevel INFO

    # Authentication:
    #LoginGraceTime 2m
    #PermitRootLogin prohibit-password
    PermitRootLogin yes # 这里加上的
    #StrictModes yes
    #MaxAuthTries 6
    #MaxSessions 10

    #PubkeyAuthentication yes

    编辑完成后,【ctrl+x】,然后在“Save modified buffer? 后面输入’y’,回车即可。

    输入sudo systemctl restart ssh重启ssh服务。

  6. 关闭ssh登录工具,然后用root用户登录。

  7. 安装中文包:

    root@ubuntu:~# sudo apt-get install language-pack-zh-hans # 输入的命令
    Reading package lists... Done
    Building dependency tree... Done
    ...
    Generating locales (this might take a while)...
    zh_CN.UTF-8... done
    zh_SG.UTF-8... done
    Generation complete.
    # 将系统的默认语言设置为中文
    root@ubuntu:~# sudo update-locale LANG=zh_CN.UTF-8
    # 重启系统
    root@ubuntu:~# reboot

    VMware虚拟机安装Ubuntu-Server版教程(超详细)_vmware安装ubuntu server-CSDN博客

ubuntu安装docker buildx

安装这个时最好是能fq操作。

  1. 安装dodcker:
    curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh ./get-docker.sh

    root@ubuntu:~# curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh ./get-docker.sh
    # Executing docker install script, commit:
    ...
    + sh -c docker version
    Client: Docker Engine - Community
    Version: 28.5.2
    API version: 1.51
    Go version: go1.25.3
    Git commit: ecc6942
    Built: Wed Nov 5 14:43:10 2025
    OS/Arch: linux/amd64
    Context: default

    Server: Docker Engine - Community
    Engine:
    Version: 28.5.2
    API version: 1.51 (minimum version 1.24)
    Go version: go1.25.3
    Git commit: 89c5e8f
    Built: Wed Nov 5 14:43:10 2025
    OS/Arch: linux/amd64
    Experimental: false
    containerd:
    Version: v1.7.29
    GitCommit: 442cb34bda9a6a0fed82a2ca7cade05c5c749582
    runc:
    Version: 1.3.3
    GitCommit: v1.3.3-0-gd842d771
    docker-init:
    Version: 0.19.0
    GitCommit: de40ad0
    root@ubuntu:~#
  2. 安装插件docker-compose。
    https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    我这里下载的时间太长了,直接在电脑上下载的docker-compose-linux-x86_64,然后上传到了-o /usr/local/bin/docker-compose并重命名了docker-compose

    root@ubuntu:~# sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
    0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
    0 73.0M 0 660k 0 0 2257 0 9:25:35 0:04:59 9:20:36 0^C
    # 增加权限 及建立软链接
    root@ubuntu:~# sudo chmod +x /usr/local/bin/docker-compose && sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
    # 查看docker-compose版本
    root@ubuntu:~# docker-compose version
    Docker Compose version v2.40.3
    root@ubuntu:~#
  3. 开启docker实验室特性:
    一是启用实验性功能 在 CLI 客户端中;

    # 输入:nano /etc/docker/daemon.json 新建并打开daemon.json文件
    root@ubuntu:~# nano /etc/docker/daemon.json
    # 文件中输入以下内容:
    {
    "experimental": true
    }
    # 【Ctrl+x】,然后y,回车,退出编辑

    第二个是在守护进程中启用实验性功能;

    # 创建目录
    mkdir -p ~/.docker/
    # 打开(如果不存在则创建)~/.docker/config.json,输入以下内容
    root@ubuntu:~# nano ~/.docker/config.json
    # 以下是输入的内容
    {
    "experimental": "enabled"
    }
    # 【Ctrl+x】,y,回车,完成编辑
  4. 查看是否开启成功:

    # 加载 daemon.json 文件
    root@ubuntu:~# systemctl daemon-reload
    # 重启docker 服务
    root@ubuntu:~# systemctl restart docker
    # 查看版本信息
    root@ubuntu:~# docker version
    Client: Docker Engine - Community
    Version: 28.5.2
    API version: 1.51
    Go version: go1.25.3
    Git commit: ecc6942
    Built: Wed Nov 5 14:43:10 2025
    OS/Arch: linux/amd64
    Context: default

    Server: Docker Engine - Community
    Engine:
    Version: 28.5.2
    API version: 1.51 (minimum version 1.24)
    Go version: go1.25.3
    Git commit: 89c5e8f
    Built: Wed Nov 5 14:43:10 2025
    OS/Arch: linux/amd64
    Experimental: true # 这里为true,说明开启成功
    containerd:
    Version: v1.7.29
    GitCommit: 442cb34bda9a6a0fed82a2ca7cade05c5c749582
    runc:
    Version: 1.3.3
    GitCommit: v1.3.3-0-gd842d771
    docker-init:
    Version: 0.19.0
    GitCommit: de40ad0
    root@ubuntu:~#
  5. 安装docker buildx插件:
    直接从Releases · docker/buildx下载:buildx-v0.30.0-rc1.linux-amd64并放到指定目录。

# 创建目录,并将下载的buildx-v0.30.0-rc1.linux-amd64重命名为docker-buildx放此目录下
root@ubuntu:~# mkdir -p ~/.docker/cli-plugins
# 移动刚下载的文件
cp "/bash/docker/buildx-v0.30.0-rc1.linux-amd64" "/root/.docker/cli-plugins/docker-buildx"
# 增加执行权限
root@ubuntu:~# chmod +x "/root/.docker/cli-plugins/docker-buildx"
# 确认安装成功 docker buildx ls
root@ubuntu:~# docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default* docker
\_ default \_ default running v0.25.2 linux/amd64 (+3), linux/386
root@ubuntu:~#
  1. 安装qemu模拟器:从上面可以看出,buildx没有显示多种平台的支持,只支持linux/amd64架构的平台,那么就需要安装模拟器,现在dockers 官方文档只说明了, buildx会包含再docker destop for MAC & windows默认包含buildx。在此查看docker/binfmt - Docker Image | Docker Hub模拟器对应的仓库名称是tonistiigi/binfmt:latest最新版的tag。

    # 安装多平台架构 :
    root@ubuntu:~# docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
    # 查看安装
    root@ubuntu:~# docker buildx ls
    NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
    default* docker
    \_ default \_ default running v0.25.2 linux/amd64 (+3), linux/arm64, linux/arm (+2), linux/ppc64le, (3 more)
    root@ubuntu:~#

    也可以利用: docker run --privileged --rm tonistiigi/binfmt --install all安装所有的平台架构。

    root@ubuntu:~# docker run --privileged --rm tonistiigi/binfmt --install all
    Unable to find image 'tonistiigi/binfmt:latest' locally
    latest: Pulling from tonistiigi/binfmt
    f4700b809f99: Pull complete
    2adec5d296ac: Pull complete
    Digest: sha256:30cc9a4d03765acac9be2ed0afc23af1ad018aed2c28ea4be8c2eb9afe03fbd1
    Status: Downloaded newer image for tonistiigi/binfmt:latest
    installing: mips64le OK
    installing: loong64 OK
    installing: mips64 OK
    {
    "supported": [
    "linux/amd64",
    "linux/amd64/v2",
    "linux/amd64/v3",
    "linux/arm64",
    "linux/riscv64",
    "linux/ppc64le",
    "linux/s390x",
    "linux/386",
    "linux/mips64le",
    "linux/mips64",
    "linux/loong64",
    "linux/arm/v7",
    "linux/arm/v6"
    ],
    "emulators": [
    "python3.12",
    "qemu-aarch64",
    "qemu-arm",
    "qemu-loongarch64",
    "qemu-mips64",
    "qemu-mips64el",
    "qemu-ppc64le",
    "qemu-riscv64",
    "qemu-s390x"
    ]
    }
    root@ubuntu:~# docker buildx ls
    NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
    default* docker
    \_ default \_ default running v0.25.2 linux/amd64 (+3), linux/arm64, linux/arm (+2), linux/ppc64le, (6 more)
    root@ubuntu:~#
  2. 如果你的环境不能联网,则需先在外网环境下载好镜像,导入内网之后,再安装:

    # 外网下载镜像,注意(如果你的内网环境机器是arm架构,就下载arm版本,如果你的内网环境机器是amd架构,就下载amd版本;这里我下载的是arm版本)
    $ docker pull tonistiigi/binfmt:latest@sha256:01882a96113f38b1928a5797c52f7eaa7e39acf6cc15ec541c6e8428f3c2347d
    # 导出镜像
    $ docker save -o tonistiigi_binfmt_arm64.tar f1d8c13be37e
    # 将导出的镜像上传至内网服务器
    $ scp tonistiigi_binfmt_arm64.tar xxxx:/xxx
    # 在内网机器执行如下命令,导入镜像
    $ docker load -i tonistiigi_binfmt_arm64.tar
    # 安装模拟器
    $ docker run --privileged --rm tonistiigi/binfmt --install all

    # 验证是否安装成功
    $ docker buildx ls
    default docker
    default default running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6

    # 验证arm机器上的amd模拟器是否安装成功,则执行如下命令,输出结果包含enable即可
    $ cat /proc/sys/fs/binfmt_misc/qemu-x86_64
    enabled

    # 如果你是amd机器,需要验证arm模拟器是否安装成功,则执行如下命令,输出结果包含enable即可
    $ cat /proc/sys/fs/binfmt_misc/qemu-aarch64
    enabled
  3. 官网推荐是通过镜像 tonistiigi/binfmt 来操作,常用操作命令如下:

查看支持的架构和模拟器列表
docker run --privileged --rm tonistiigi/binfmt:master
安装所有架构模拟器
docker run --privileged --rm tonistiigi/binfmt:master --install all
安装指定架构的
docker run --privileged --rm tonistiigi/binfmt:master --install arm64,riscv64,arm
安装arm64
docker run --privileged --rm tonistiigi/binfmt:master --install arm64,arm
删除所有架构
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-*
删除指定架构
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64
查看版本
docker run --privileged --rm tonistiigi/binfmt:master --version
查看帮助
docker run --privileged --rm tonistiigi/binfmt:master --help

参考文档:docker buildx — GoodCommand 2.0 文档

参考文档:Docker buildx 安装-

参考文档:在 X86_64(amd64) 平台上的docker支持打包跨平台的镜像(如arm64)

安装nodejs

使用 NodeSource PPA 安装:

  1. 如果需要安装特定版本的 Node.js,NodeSource PPA 是一个理想的选择。利用NodeSource 安装nodejs的同时会安装npm下载并执行 NodeSource 安装脚本(以 v22.x 为例):
# 安装NodeSource软件源 和 密钥 keyrings;setup_22.x 这个22的版本可以修改任意版本号。 
root@ubuntu:~# curl -sL https://deb.nodesource.com/setup_22.x | sudo -E bash -
2025-11-08 02:24:52 - Installing pre-requisites
命中:1 http://security.ubuntu.com/ubuntu noble-security InRelease
....
下列【新】软件包将被安装:
apt-transport-https
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
...
正在读取状态信息... 完成
所有软件包均为最新。
2025-11-08 02:25:23 - Repository configured successfully.
2025-11-08 02:25:23 - To install Node.js, run: apt install nodejs -y
2025-11-08 02:25:23 - You can use N|solid Runtime as a node.js alternative
2025-11-08 02:25:23 - To install N|solid Runtime, run: apt install nsolid -y
# 上面完成之后,生成 "/etc/apt/sources.list.d/nodesource.list" 加一个包源
# 在 /usr/share/keyrings/nodesource.gpg 上增加一个 密钥
# 正式安装 nodejs
root@ubuntu:~# sudo apt install nodejs
正在读取软件包列表... 完成
下列【新】软件包将被安装:
nodejs
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
获取:1 https://deb.nodesource.com/node_22.x nodistro/main amd64 nodejs amd64 22.21.0-1nodesource1 [37.6 MB]
已下载 37.6 MB,耗时 12秒 (3,113 kB/s)
....
No VM guests are running outdated hypervisor (qemu) binaries on this host.
# 确认安装成功
root@ubuntu:~# node --version
v22.21.0
# 确认npm 安装成功
root@ubuntu:~# npm --version
10.9.4
root@ubuntu:~#
  1. 执行 NodeSource 安装脚本:
    cd ~
    curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
    sudo bash nodesource_setup.sh
    sudo apt install nodejs
    node -v

安装yarn

Yarn 依赖于 Node.js,所有要先安装好nodejs,安装yarn官方中文文档,如果您已经安装了 Node.js 和 npm,可以直接使用 npm 安装 Yarn:

  1. 利用npm安装yarn:

    # 利用npm安装yarn
    root@ubuntu:~# npm install --global yarn
    added 1 package in 3s
    npm notice
    npm notice New major version of npm available! 10.9.4 -> 11.6.2
    npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.6.2
    npm notice To update run: npm install -g npm@11.6.2
    npm notice
    root@ubuntu:~# yarn --version
    1.22.22
    root@ubuntu:~#
  2. 使用 APT 安装:这个要先添加apt仓库

    # 添加apt仓库
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://dl.yarnpkg.com/debian $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/yarn.list
    # 更新包列表以识别新添加的 Yarn 存储库
    sudo apt update
    # 安装 yarn
    sudo apt install yarn

利用buildx打包sub-web镜像

使用Buildx构建并指定AMD64平台:命令说明

docker buildx build -t subseb:latest -f /bash/sub-web/Dockerfile .
# 打包生成一个 tar 文件
docker buildx build --platform linux/arm64 -t subweb:arm64 --output type=tar,dest=./myimage-arm64.tar .
# 单平台并加载到本地docker上
docker buildx build --platform linux/arm64 -t subweb:arm64 --load .
# 说明
docker buildx build \
--platform linux/arm64 \
-f /bash/sub-web/Dockerfile \
-t your-image:tag \
--load . # 或使用 --push 推送至仓库
  • 参数说明
    • --platform linux/arm64:指定目标平台为ARM64。
    • -f /bash/sub-web/Dockerfile:Dockerfile文件路径
    • -t your-image:tag:镜像取的名字,如:subweb:amd64
    • --output type=tar,dest=./myimage-amd64.tar:输出:输出的类型,路径
    • --load:将镜像加载到本地Docker(仅适用于单平台构建)。
    • --push:直接推送到远程仓库(推荐用于多平台或生产环境)。
    • .:是打包本目录

sub-web源码打包镜像:

CareyWang/sub-web

修改sub-web:docker搭建Clash订阅转换sub+subweb+myurl教程

修改sub-web:自建Clash订阅转换 - Subconverter+Subweb+MyUrls搭建教程 - 全docker完成 - mihomo内核

root@ubuntu:~# cd /mnt
root@ubuntu:/mnt# git clone https://github.com/CareyWang/sub-web.git
正克隆到 'sub-web'...
处理 delta 中: 100% (255/255), 完成.
root@ubuntu:/bash# cd "/bash/sub-web/"
# 打包 sub-web的amd64平台镜像
root@ubuntu:/bash/sub-web# docker buildx build --platform linux/amd64 -t subweb:amd64 --output type=tar,dest=./myimage-amd64.tar .
[+] Building 140.9s (13/13) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 268B 0.0s
=> [internal] load metadata for docker.io/library/nginx:1.24-alpine 1.8s
=> [internal] load metadata for docker.io/library/node:20-alpine 1.8s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [build 1/5] FROM docker.io/library/node:20-alpine@sha256:6178e78b972f79 20.6s
=> => resolve docker.io/library/node:20-alpine@sha256:6178e78b972f79c335df2 0.0s
=> => sha256:6178e78b972f79c335df281f4b7674a2d85071aae2af02 7.67kB / 7.67kB 0.0s
=> => sha256:be8d32d651b3e0c9c2b28fdc1d3888408125d703232013 1.72kB / 1.72kB 0.0s
=> => sha256:2b56f2779663b9e1a77bdb5235dc31f1a81e534ccab1c1 6.42kB / 6.42kB 0.0s
=> => sha256:2d35ebdb57d9971fea0cac1582aa78935adf8058b2cc32 3.80MB / 3.80MB 5.0s
=> => sha256:60e45a9660cfaebbbac9bba98180aa28b3966b7f246 42.75MB / 42.75MB 18.5s
=> => extracting sha256:2d35ebdb57d9971fea0cac1582aa78935adf8058b2cc32db163 0.1s
=> => sha256:e74e4ed823e9560b3fe51c0cab47dbfdfc4b1245360431 1.26MB / 1.26MB 8.0s
=> => sha256:da04d522c98fe12816b2bcddf8413fca73645f8fa60f287c67 444B / 444B 7.7s
=> => extracting sha256:60e45a9660cfaebbbac9bba98180aa28b3966b7f2462d132c46 1.9s
=> => extracting sha256:e74e4ed823e9560b3fe51c0cab47dbfdfc4b12453604319408e 0.0s
=> => extracting sha256:da04d522c98fe12816b2bcddf8413fca73645f8fa60f287c672 0.0s
=> [stage-1 1/2] FROM docker.io/library/nginx:1.24-alpine@sha256:77e5d4a6ad 7.6s
=> => resolve docker.io/library/nginx:1.24-alpine@sha256:77e5d4a6ad906c5d37 0.0s
=> => sha256:249f59e1dec7f7eacbeba4bb9215b8000e4bdbb672af 11.42kB / 11.42kB 0.0s
=> => sha256:77e5d4a6ad906c5d3793764085706577fa705b1dc6f244 9.06kB / 9.06kB 0.0s
=> => sha256:e7ece7ddc2e44b2af69a1aa282047794bb31287a960f6c 2.31kB / 2.31kB 0.0s
=> => sha256:3c854c8cbf469fda815b8f6183300c07cfa2fbb5703859 3.38MB / 3.38MB 1.6s
=> => sha256:de5d475193dd13b444c2e58fc772d8a3297e370eb90e67 1.80MB / 1.80MB 1.5s
=> => sha256:b407bcc8063852cf7b980fa6d83d6caa2c17b2fa4c10e87835 625B / 625B 1.3s
=> => sha256:da33b1ad0ac4b49641e40469216939f6488c1d8116b2513ba2 954B / 954B 1.9s
=> => sha256:a0fbd691d7c1a07fbdeb8b338578f4e199a49e2491eff17110 768B / 768B 2.1s
=> => extracting sha256:3c854c8cbf469fda815b8f6183300c07cfa2fbb5703859ca79a 0.1s
=> => sha256:16eaaaf5f1c0db05389b2c1c2d90db8c9154289520fad3 1.40kB / 1.40kB 2.3s
=> => extracting sha256:de5d475193dd13b444c2e58fc772d8a3297e370eb90e67e4830 0.2s
=> => sha256:5e845cc16269ce694cab9e13e1bdc03d82091f380f1b 11.67MB / 11.67MB 6.9s
=> => extracting sha256:b407bcc8063852cf7b980fa6d83d6caa2c17b2fa4c10e87835d 0.0s
=> => extracting sha256:da33b1ad0ac4b49641e40469216939f6488c1d8116b2513ba2c 0.0s
=> => extracting sha256:a0fbd691d7c1a07fbdeb8b338578f4e199a49e2491eff171105 0.0s
=> => extracting sha256:16eaaaf5f1c0db05389b2c1c2d90db8c9154289520fad38d580 0.0s
=> => extracting sha256:5e845cc16269ce694cab9e13e1bdc03d82091f380f1b2975e69 0.6s
=> [internal] load build context 0.0s
=> => transferring context: 4.98kB 0.0s
=> [build 2/5] WORKDIR /app 0.2s
=> [build 3/5] COPY . . 0.0s
=> [build 4/5] RUN yarn install 82.4s
=> [build 5/5] RUN yarn build 35.0s
=> [stage-1 2/2] COPY --from=build /app/dist /usr/share/nginx/html 0.0s
=> exporting to client tarball 0.3s
=> => sending tarball 0.2s
root@ubuntu:/bash/sub-web#

sub-web打包arm64镜像

打包这个镜像时,开始buildx只安装了,指定结构的平台,居然没有成功。
docker run --privileged --rm tonistiigi/binfmt:master --install arm64

提示是平台错误:

 => ERROR [build 4/5] RUN yarn install                                        0.3s
------
> [build 4/5] RUN yarn install:
0.261 exec /bin/sh: exec format error
------
Dockerfile:5
--------------------
3 | WORKDIR /app
4 | COPY . .
5 | >>> RUN yarn install
6 | RUN yarn build
7 |
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c yarn install" did not complete successfully: exit code: 255

后来安装了所有平台 docker run --privileged --rm tonistiigi/binfmt:master --install all
才打包成功。

安装下面这个:

docker run --privileged --rm tonistiigi/binfmt:master --install arm64,arm

root@ubuntu:/bash/sub-web# docker buildx build --platform linux/arm64 -t subweb:arm64 --output type=tar,dest=./myimage-arm64.tar .
[+] Building 607.5s (13/13) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 268B 0.0s
=> [internal] load metadata for docker.io/library/nginx:1.24-alpine 0.4s
=> [internal] load metadata for docker.io/library/node:20-alpine 0.2s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [build 1/5] FROM docker.io/library/node:20-alpine@sha256:6178e78b972f79c 0.0s
=> CACHED [stage-1 1/2] FROM docker.io/library/nginx:1.24-alpine@sha256:77e 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 5.02kB 0.0s
=> CACHED [build 2/5] WORKDIR /app 0.0s
=> CACHED [build 3/5] COPY . . 0.0s
=> [build 4/5] RUN yarn install 221.2s
=> [build 5/5] RUN yarn build 384.7s
=> [stage-1 2/2] COPY --from=build /app/dist /usr/share/nginx/html 0.0s
=> exporting to client tarball 0.6s
=> => sending tarball 0.5s
root@ubuntu:/bash/sub-web#

linux登陆docker

账号注册之后,我们一般再 linux 上操作,在 linux 上先登陆https://hub.docker.com

root@ubuntu:~# docker login -u 195569807@qq.com

i Info → A Personal Access Token (PAT) can be used instead.
To create a PAT, visit https://app.docker.com/settings

# 输入密码时不显示
Password:

WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/
# 这个说明登录成功
Login Succeeded
root@ubuntu:~#

在hub.docker.com上面新建镜像仓库,输入仓库名称和描述,可以选择公共 public 的仓库和私有 private 的仓库

上传自己制作的docker镜像到仓库

# 先查看本地镜像  docker images
root@ubuntu:/bash/sub-web# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
subweb arm64 e61a92520437 8 minutes ago 48.8MB
tonistiigi/binfmt master a91b96d3f66b 2 weeks ago 83.3MB
# 在上传之前,先给本地镜像打个tag标签,相当于重新复制镜像并重命名为docker账户名/仓库名称
# docker tag 本地镜像:tag docker账号/docker仓库:tag
root@ubuntu:/bash/sub-web# docker tag subweb:arm64 jinwei26/subweb:arm64
# 上传本地镜像标签到镜像仓库 docker push docker 账号/仓库名称:tagname
root@ubuntu:/bash/sub-web# docker push jinwei26/subweb:arm64
The push refers to repository [docker.io/jinwei26/subweb]
972b2506b26b: Pushed
831688828271: Mounted from library/nginx
f703cc7a0e63: Mounted from library/nginx
c1a9cf18a197: Mounted from library/nginx
8d29e380f219: Mounted from library/nginx
b6663d435f61: Mounted from library/nginx
e49d7f89f9f8: Mounted from library/nginx
458ecd8dac67: Mounted from library/nginx
arm64: digest: sha256:d98054d56140b4d84bbae5af5b384b89358823bf9011787e4001edf84d19714b size: 1992
root@ubuntu:/bash/sub-web#

docker push jinwei26/subweb:arm64

docker tag subweb:arm64 jinwei26/subweb:arm64

docker学习7-Dockerfile制作自己的镜像文件

docker学习上海-悠悠 - 博客园

直接安装QEMU / binfmt

  1. 安装 QEMU / binfmt(在 Debian/Ubuntu 上):
sudo apt-get update
sudo apt-get install -y qemu-user-static binfmt-support
  1. 注册 QEMU 二进制到内核的 binfmt_misc(这步让内核能自动用 QEMU 运行 ARM 二进制):
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

如果你用的是 rootless docker 或者有安全策略,可能需要额外权限或调整。

  1. 创建并启用 buildx 构建器(推荐使用 docker-container 驱动):
docker buildx create --name mybuilder --driver docker-container --use
docker buildx inspect --bootstrap
  1. 构建(示例:同时构建 arm64 与 armv7 并推到 registry):
docker buildx build \
--platform linux/arm64,linux/arm/v7 \
-t yourhubname/yourimage:tag \
--push \
.

说明:

  • --platform 指定目标架构;也可以只写 linux/arm64
  • --push 会直接把多架构镜像推到 registry(会创建 manifest)。
  • 若只想把单一架构的镜像加载到本地 docker,可以用 --load(注意:--load 不能与多个平台一起使用,只能单个平台)。

参考文档:在 X86_64(amd64) 平台上的docker支持打包跨平台的镜像(如arm64)