Ubuntu安装docker buildx打包全平台镜像sub-web镜像
VM安装Ubuntu
获取Ubuntu服务器版 | Ubuntu下载Server版本,版本架构随便自己选,一般应该是amd64的。
新建虚拟机:
- 新建虚拟机我们可以从【左侧侧边栏】鼠标右键,选择 【新建虚拟机(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)】查看你虚拟机的配置,也可以直接点【完成】
安装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.这就安装完成了。
在安装的过程中,有的也可能出现,这个界面是告诉你,系统有更新了,问你要不要更新一下。这里我们先直接选择
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操作
启动虚拟机,输入我们刚刚创建的
ubuntu用户,即可登录,输入ip addr show查看ip地址,以ssh连接。使用远程工具MobaXterm上登录,
# 输入用户名
login as: xxx
# 输入上面设置的密码,密码不显示,密码输完回车就可以了
xxx@192.168.50.23's password:开户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:~$传统方式切换root用户,
缺点:只能当前终端窗口有效。每次打开新的终端窗口都需要进行命令切换。# 输入:su root
xxx@ubuntu:~$ su root
# 输入root 密码
Password:
root@ubuntu:/home/xxx#直接用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服务。关闭ssh登录工具,然后用root用户登录。
安装中文包:
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:~# rebootVMware虚拟机安装Ubuntu-Server版教程(超详细)_vmware安装ubuntu server-CSDN博客
ubuntu安装docker buildx
安装这个时最好是能fq操作。
安装dodcker:
curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh ./get-docker.shroot@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:~#安装插件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-composeroot@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:~#开启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,回车,完成编辑查看是否开启成功:
# 加载 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:~#安装docker buildx插件:
直接从Releases · docker/buildx下载:buildx-v0.30.0-rc1.linux-amd64并放到指定目录。
# 创建目录,并将下载的buildx-v0.30.0-rc1.linux-amd64重命名为docker-buildx放此目录下 |
安装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:~#如果你的环境不能联网,则需先在外网环境下载好镜像,导入内网之后,再安装:
# 外网下载镜像,注意(如果你的内网环境机器是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官网推荐是通过镜像
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 安装:
- 如果需要安装特定版本的 Node.js,NodeSource PPA 是一个理想的选择。利用NodeSource 安装nodejs的同时会安装npm下载并执行 NodeSource 安装脚本(以 v22.x 为例):
# 安装NodeSource软件源 和 密钥 keyrings;setup_22.x 这个22的版本可以修改任意版本号。 |
- 执行 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:
利用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:~#使用 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 . |
- 参数说明
--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 |
sub-web打包arm64镜像
打包这个镜像时,开始buildx只安装了,指定结构的平台,居然没有成功。 docker run --privileged --rm tonistiigi/binfmt:master --install arm64
提示是平台错误:
=> ERROR [build 4/5] RUN yarn install 0.3s |
后来安装了所有平台 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 . |
linux登陆docker
账号注册之后,我们一般再 linux 上操作,在 linux 上先登陆https://hub.docker.com
root@ubuntu:~# docker login -u 195569807@qq.com |
在hub.docker.com上面新建镜像仓库,输入仓库名称和描述,可以选择公共 public 的仓库和私有 private 的仓库
上传自己制作的docker镜像到仓库
# 先查看本地镜像 docker images |
docker push jinwei26/subweb:arm64
docker tag subweb:arm64 jinwei26/subweb:arm64
docker学习7-Dockerfile制作自己的镜像文件
docker学习上海-悠悠 - 博客园
直接安装QEMU / binfmt
- 安装 QEMU / binfmt(在 Debian/Ubuntu 上):
sudo apt-get update |
- 注册 QEMU 二进制到内核的 binfmt_misc(这步让内核能自动用 QEMU 运行 ARM 二进制):
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes |
如果你用的是 rootless docker 或者有安全策略,可能需要额外权限或调整。
- 创建并启用 buildx 构建器(推荐使用
docker-container驱动):
docker buildx create --name mybuilder --driver docker-container --use |
- 构建(示例:同时构建 arm64 与 armv7 并推到 registry):
docker buildx build \ |
说明:
--platform指定目标架构;也可以只写linux/arm64。--push会直接把多架构镜像推到 registry(会创建 manifest)。- 若只想把单一架构的镜像加载到本地 docker,可以用
--load(注意:--load不能与多个平台一起使用,只能单个平台)。
参考文档:在 X86_64(amd64) 平台上的docker支持打包跨平台的镜像(如arm64)