-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #581 from wayne-cheng/optimize-dockerfile
优化Dockerfile,支持真正的跨平台构建镜像
- Loading branch information
Showing
5 changed files
with
127 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,31 @@ | ||
FROM ubuntu:20.04 | ||
MAINTAINER chenjh "842761733@qq.com" | ||
# 内置一些常用的中文字体,避免普遍性乱码 | ||
COPY fonts/* /usr/share/fonts/chinese/ | ||
RUN apt-get clean && apt-get update &&\ | ||
sed -i 's/http:\/\/archive.ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list &&\ | ||
sed -i 's/# deb/deb/g' /etc/apt/sources.list &&\ | ||
apt-get install -y --reinstall ca-certificates &&\ | ||
apt-get clean && apt-get update &&\ | ||
apt-get install -y locales language-pack-zh-hans &&\ | ||
localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 && locale-gen zh_CN.UTF-8 &&\ | ||
FROM ubuntu:24.04 | ||
|
||
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources &&\ | ||
sed -i 's@//security.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources &&\ | ||
sed -i 's@//ports.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources &&\ | ||
apt-get update &&\ | ||
export DEBIAN_FRONTEND=noninteractive &&\ | ||
apt-get install -y tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\ | ||
apt-get install -y fontconfig ttf-mscorefonts-installer ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy &&\ | ||
apt-get install -y wget &&\ | ||
cd /tmp &&\ | ||
wget https://kkview.cn/resource/server-jre-8u251-linux-x64.tar.gz &&\ | ||
tar -zxf /tmp/server-jre-8u251-linux-x64.tar.gz && mv /tmp/jdk1.8.0_251 /usr/local/ &&\ | ||
apt-get install -y --no-install-recommends openjdk-8-jre tzdata locales xfonts-utils fontconfig libreoffice-nogui &&\ | ||
echo 'Asia/Shanghai' > /etc/timezone &&\ | ||
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\ | ||
localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 &&\ | ||
locale-gen zh_CN.UTF-8 &&\ | ||
# 安装微软字体 | ||
# apt-get install -y --no-install-recommends ttf-mscorefonts-installer &&\ | ||
# 安装文泉驿字体 | ||
# apt-get install -y --no-install-recommends ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy &&\ | ||
# 清理临时文件 | ||
apt-get autoremove -y &&\ | ||
apt-get clean &&\ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# 安装 libreoffice | ||
apt-get install -y libxrender1 libxinerama1 libxt6 libxext-dev libfreetype6-dev libcairo2 libcups2 libx11-xcb1 libnss3 &&\ | ||
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.5.3.2/deb/x86_64/LibreOffice_7.5.3.2_Linux_x86-64_deb.tar.gz -cO libreoffice_deb.tar.gz &&\ | ||
tar -zxf /tmp/libreoffice_deb.tar.gz && cd /tmp/LibreOffice_7.5.3.2_Linux_x86-64_deb/DEBS &&\ | ||
dpkg -i *.deb &&\ | ||
# 内置一些常用的中文字体,避免普遍性乱码. 建议安装思源字体 https://zh-cn.libreoffice.org/download/fonts/ | ||
ADD fonts/* /usr/share/fonts/chinese/ | ||
|
||
# 清理临时文件 | ||
rm -rf /tmp/* && rm -rf /var/lib/apt/lists/* &&\ | ||
cd /usr/share/fonts/chinese &&\ | ||
RUN cd /usr/share/fonts/chinese &&\ | ||
# 安装字体 | ||
mkfontscale &&\ | ||
mkfontdir &&\ | ||
fc-cache -fv | ||
|
||
ENV JAVA_HOME /usr/local/jdk1.8.0_251 | ||
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar | ||
ENV PATH $PATH:$JAVA_HOME/bin | ||
ENV LANG zh_CN.UTF-8 | ||
ENV LC_ALL zh_CN.UTF-8 | ||
CMD ["/bin/bash"] | ||
ENV LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 构建说明 | ||
|
||
由于 kkfileview 的基础运行环境很少变动且制作耗时较久,而 kkfileview 本身代码开发会频繁改动,因此把制作其 Docker 镜像的步骤拆分为两次: | ||
|
||
首先制作 kkfileview 的基础镜像(kkfileview-jdk)。 | ||
|
||
然后使用 kkfileview-jdk 作为基础镜像进行构建,加快 kkfileview docker 镜像构建与发布。 | ||
|
||
执行如下命令即可构建基础镜像: | ||
> 这里镜像 tag 以 4.4.0 为例,本项目所维护的 Dockerfile 文件考虑了跨平台兼容性。 如果你需要用到 arm64 架构镜像, 则在arm64 架构机器上同样执行下面的构建命令即可 | ||
|
||
```shell | ||
docker build --tag keking/kkfileview-jdk:4.4.0 . | ||
``` | ||
|
||
|
||
|
||
## 跨平台构建 | ||
|
||
`docker buildx` 支持在一台机器上构建出多种平台架构的镜像。推荐使用该能力进行跨平台的镜像构建。 | ||
例如,执行 `docker buildx build` 命令时加上 `--platform=linux/arm64` 参数即可构建出 arm64 架构镜像。这极大方便了那些没有arm64 架构机器却想构建 arm64 架构镜像的用户。 | ||
|
||
> 当前本项目仅支持构建 linux/amd64 和 linux/arm64 两种平台架构的镜像 | ||
> buildx 的 builder driver 可以使用默认的 `docker` 类型, 若使用 `docker-container` 类型可以支持并行构建多种架构, 本文不再赘述, 有兴趣可以自行了解。参考 [Docker Buildx | Docker Documentation](https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images) | ||
|
||
**前提要求** | ||
|
||
以当前机器为 amd64 (x86_64)架构为例。需要开启 docker 的 buildx 特性,以及开启 Linux 的 QEMU 用户模式: | ||
|
||
> 使用 WSL2 的 Windows 用户如果安装了最新的 DockerDesktop, 则这些前提要求已满足, 无需额外下述设置。 | ||
|
||
1. 安装 docker buildx 客户端插件: | ||
> docker 版本要求 >=19.03 | ||
|
||
若已安装, 则跳过。详情参考 https://github.com/docker/buildx | ||
|
||
2. 开启 QEMU 的用户模式功能, 并安装其它平台的模拟器: | ||
> Linux 内核要求 >=4.8 | ||
|
||
使用 `tonistiigi/binfmt` 镜像可快速开启并安装模拟器,执行下面命令: | ||
|
||
```shell | ||
docker run --privileged --rm tonistiigi/binfmt --install all | ||
``` | ||
|
||
现在就可以愉快地开始构建了,构建命令示例: | ||
|
||
```shell | ||
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-jdk:4.4.0 --push . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Build Instructions | ||
|
||
Since the base runtime environment for kkfileview rarely changes and takes a long time to build, while the kkfileview code itself is frequently updated, the process of building its Docker image is split into two steps: | ||
|
||
First, create the base image for kkfileview (kkfileview-jdk). | ||
|
||
Then, use kkfileview-jdk as the base image to build and speed up the kkfileview Docker image build and release process. | ||
|
||
To build the base image, run the following command: | ||
|
||
> In this example, the image tag is 4.4.0. The Dockerfile maintained in this project considers cross-platform compatibility. If you need an arm64 architecture image, run the same build command on an arm64 architecture machine. | ||
|
||
```shell | ||
docker build --tag keking/kkfileview-jdk:4.4.0 . | ||
``` | ||
|
||
|
||
|
||
## Cross-Platform Build | ||
|
||
`docker buildx` supports building images for multiple platform architectures on a single machine. It is recommended to use this capability for cross-platform image builds. | ||
For example, adding the `--platform=linux/arm64` parameter when executing the `docker buildx build` command will allow you to build an arm64 architecture image. This is particularly convenient for users who want to build arm64 images but don't have an arm64 machine. | ||
|
||
> Currently, this project only supports building images for the linux/amd64 and linux/arm64 architectures. | ||
> The buildx builder driver can use the default `docker` type, but if you use the `docker-container` type, you can build multiple architectures in parallel. This README will not cover that in detail, you can learn more on your own. Refer to [Docker Buildx | Docker Documentation](https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images) | ||
|
||
**Prerequisites** | ||
|
||
Assuming the current machine is amd64 (x86_64) architecture, you'll need to enable the docker buildx feature and enable Linux QEMU user mode: | ||
|
||
> Windows users with WSL2 who have installed a recent version of Docker Desktop will already meet these prerequisites, so no additional setup is required. | ||
|
||
1. Install the docker buildx client plugin: | ||
|
||
> Docker version >=19.03 is required. | ||
|
||
If it's already installed, you can skip this step. For more details, refer to https://github.com/docker/buildx. | ||
|
||
2. Enable QEMU user mode and install emulators for other platforms: | ||
|
||
> Linux kernel version >=4.8 is required. | ||
|
||
You can quickly enable and install emulators using the tonistiigi/binfmt image by running the following command: | ||
|
||
```shell | ||
docker run --privileged --rm tonistiigi/binfmt --install all | ||
``` | ||
|
||
Now you can enjoy the building. Here’s an example build command: | ||
|
||
```shell | ||
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-jdk:4.4.0 --push . | ||
``` |
This file was deleted.
Oops, something went wrong.