feat: 更新支持多架构编译,切换使用 Debian 11-slim
This commit is contained in:
+89
-31
@@ -1,57 +1,109 @@
|
||||
# Ver: 1.8 by Endial Fang (endial@126.com)
|
||||
# Ver: 1.9 by Endial Fang (endial@126.com)
|
||||
#
|
||||
|
||||
# 默认变量 ========================================================================
|
||||
# 该部分变量为系统根据编译命令默认设置
|
||||
|
||||
# `TARGETPLATFORM`:构建后的目标平台信息。如 `linux/amd64`,`linux/arm/v7`,`windows/amd64`
|
||||
# `TARGETOS`:目标平台信息(TARGETPLATFORM)中的操作系统部分,如:`linux`、`windows`
|
||||
# `TARGETARCH`:目标平台信息(TARGETPLATFORM)中的平台架构部分,如:`amd64`、`arm`
|
||||
# `TARGETVARIANT`:目标平台信息(TARGETPLATFORM)中的版本变体部分,如:`v7`
|
||||
# `BUILDPLATFORM`:用于构建的节点平台信息
|
||||
# `BUILDOS`:用于构建的节点平台信息(BUILDPLATFORM)中的操作系统部分
|
||||
# `BUILDARCH`用于构建的节点平台信息(BUILDPLATFORM)中的平台架构部分
|
||||
# `BUILDVARIANT`用于构建的节点平台信息(BUILDPLATFORM)中的版本变体部分
|
||||
|
||||
# 可变参数 ========================================================================
|
||||
# 该部分变量,在编译命令中通过 `--build-arg` 传入;如果未设置,则使用下面对应的默认值
|
||||
|
||||
# 设置当前应用名称及版本
|
||||
ARG app_name=debian-buster
|
||||
ARG app_version=10
|
||||
ARG APP_NAME=debian
|
||||
ARG APP_VER=11
|
||||
|
||||
# 设置默认仓库地址,默认为 阿里云 仓库
|
||||
ARG registry_url="registry.cn-shenzhen.aliyuncs.com"
|
||||
# 设置默认仓库地址,默认为本地仓库
|
||||
ARG REGISTRY_URL="docker.colovu.com"
|
||||
|
||||
# 设置 apt-get 源:default / tencent / ustc / aliyun / huawei
|
||||
ARG apt_source=aliyun
|
||||
# 设置 apt-get 源:default / ustc / aliyun
|
||||
ARG APT_SOURCE=aliyun
|
||||
|
||||
# 编译镜像时指定用于加速的本地服务器地址
|
||||
ARG local_url=""
|
||||
# 编译镜像时指定用于加速的本地软件包存储服务器地址
|
||||
ARG LOCAL_URL=""
|
||||
|
||||
|
||||
# 1. 生成镜像 =====================================================================
|
||||
FROM debian:buster-slim
|
||||
# 0. 预处理 ======================================================================
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ${REGISTRY_URL}/library/debian:${APP_VER}-slim as builder
|
||||
|
||||
# 声明需要使用的全局可变参数
|
||||
ARG app_name
|
||||
ARG app_version
|
||||
ARG registry_url
|
||||
ARG apt_source
|
||||
ARG local_url
|
||||
|
||||
LABEL \
|
||||
"Version"="v${app_version}" \
|
||||
"Description"="Docker image for Debian OS v${app_version}(Buster)." \
|
||||
"Dockerfile"="https://github.com/colovu/docker-debian" \
|
||||
"Vendor"="Endial Fang (endial@126.com)"
|
||||
ARG APP_NAME
|
||||
ARG APP_VER
|
||||
ARG REGISTRY_URL
|
||||
ARG APT_SOURCE
|
||||
ARG LOCAL_URL
|
||||
|
||||
# 拷贝默认的通用脚本文件
|
||||
COPY prebuilds /
|
||||
|
||||
# 选择软件包源(Optional),以加速后续软件包安装
|
||||
RUN select_source ${apt_source}
|
||||
RUN select_source ${APT_SOURCE};
|
||||
|
||||
# 增加 NSS_WRAPPER 支持;安装 curl 工具
|
||||
RUN install_pkg locales apt-utils libnss-wrapper curl net-tools
|
||||
# 设置工作目录
|
||||
WORKDIR /usr/local
|
||||
|
||||
# 增加locales支持,并设置默认为 UTF-8
|
||||
#RUN install_pkg sudo wget curl git ca-certificates iproute2 net-tools nano dpkg gnupg \
|
||||
# dirmngr apt-utils apt-transport-https lsb-release iputils-ping \
|
||||
# build-essential cmake libcmocka-dev pkg-config libssl1.1 libssl-dev \
|
||||
# libtool libltdl7 libltdl-dev
|
||||
|
||||
RUN install_pkg wget ca-certificates dpkg
|
||||
|
||||
# 下载并解压软件包
|
||||
RUN set -eux; \
|
||||
appVersion=1.16; \
|
||||
appName=gosu-"$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
|
||||
appKeys="0xB42F6819007F00F88E364FD4036A9C25BF357DD4"; \
|
||||
[ ! -z ${LOCAL_URL} ] && localURL=${LOCAL_URL}/gosu; \
|
||||
appUrls="${LOCAL_URL:-}/${appVersion} \
|
||||
https://github.com/tianon/gosu/releases/download/${appVersion} \
|
||||
"; \
|
||||
download_pkg install ${appName} "${appUrls}" ; \
|
||||
chmod +x /usr/local/bin/${appName};
|
||||
|
||||
# 1. 生成镜像 =====================================================================
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ${REGISTRY_URL}/library/debian:${APP_VER}-slim
|
||||
|
||||
# 声明需要使用的全局可变参数
|
||||
ARG APP_NAME
|
||||
ARG APP_VER
|
||||
ARG REGISTRY_URL
|
||||
ARG APT_SOURCE
|
||||
ARG LOCAL_URL
|
||||
ARG TARGETARCH
|
||||
|
||||
LABEL \
|
||||
"Version"="v${APP_VER}" \
|
||||
"Description"="Docker image for Debian." \
|
||||
"Github"="https://github.com/colovu/docker-debian" \
|
||||
"Vendor"="Endial Fang (endial@126.com)"
|
||||
|
||||
# 拷贝默认的通用脚本文件
|
||||
COPY prebuilds /
|
||||
|
||||
# 从预处理过程中拷贝软件包
|
||||
COPY --from=builder /usr/local/bin/gosu-${TARGETARCH} /usr/local/bin/gosu
|
||||
|
||||
# 选择软件包源(Optional),以加速后续软件包安装
|
||||
RUN select_source ${APT_SOURCE}
|
||||
|
||||
# 增加 NSS_WRAPPER 支持
|
||||
RUN install_pkg locales apt-utils tini libnss-wrapper curl
|
||||
|
||||
# 增加locales支持,并设置默认为 UTF-8;配置时区默认为 Shanghai
|
||||
RUN set -eux; \
|
||||
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen; \
|
||||
sed -i -e 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen; \
|
||||
locale-gen; \
|
||||
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_MESSAGES=POSIX; \
|
||||
dpkg-reconfigure -f noninteractive locales;
|
||||
|
||||
# 配置时区默认为 Shanghai
|
||||
RUN set -eux; \
|
||||
dpkg-reconfigure -f noninteractive locales; \
|
||||
\
|
||||
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; \
|
||||
dpkg-reconfigure -f noninteractive tzdata;
|
||||
|
||||
@@ -59,6 +111,12 @@ ENV LANG=en_US.UTF-8 \
|
||||
LANGUAGE=en_US.UTF-8 \
|
||||
LC_ALL=en_US.UTF-8
|
||||
|
||||
# 执行预处理脚本,并验证安装的软件包
|
||||
RUN set -eux; \
|
||||
gosu nobody true; \
|
||||
gosu --version; \
|
||||
tini --version;
|
||||
|
||||
WORKDIR /
|
||||
|
||||
# 应用程序的服务命令,必须使用非守护进程方式运行。如果使用变量,则该变量必须在运行环境中存在(ENV可以获取)
|
||||
|
||||
@@ -6,24 +6,24 @@
|
||||
image_name :=colovu/debian
|
||||
|
||||
# 定义默认镜像仓库地址
|
||||
registry_url :=docker.io
|
||||
REGISTRY_URL :=docker.colovu.com
|
||||
|
||||
# 定义系统默认使用的源服务器,包含:default / tencent / ustc / aliyun / huawei
|
||||
apt_source :=tencent
|
||||
# 定义系统默认使用的源服务器,包含:default / ustc / aliyun
|
||||
APT_SOURCE :=aliyun
|
||||
|
||||
# 定义镜像TAG,类似:
|
||||
# <镜像名>:<分支名>-<7位Git ID> # Git 仓库且无文件修改直接编译
|
||||
# <镜像名>:<分支名>-<7位Git ID> # Git 仓库且无文件修改直接编译
|
||||
# <镜像名>:<分支名>-<年月日>-<时分秒> # Git 仓库有文件修改后的编译
|
||||
# <镜像名>:latest-<年月日>-<时分秒> # 非 Git 仓库编译
|
||||
current_subversion:=$(shell if [ ! `git status >/dev/null 2>&1` ]; then git rev-parse --short HEAD; else date +%y%m%d-%H%M%S; fi)
|
||||
image_tag:=$(shell if [ ! `git status >/dev/null 2>&1` ]; then git rev-parse --abbrev-ref HEAD | sed -e 's/master/latest/'; else echo "latest"; fi)-$(current_subversion)
|
||||
|
||||
build-arg:=--build-arg registry_url=$(registry_url)
|
||||
build-arg+=--build-arg apt_source=$(apt_source)
|
||||
build-arg:=--build-arg REGISTRY_URL=$(REGISTRY_URL)
|
||||
build-arg+=--build-arg APT_SOURCE=$(APT_SOURCE)
|
||||
|
||||
# 设置本地下载服务器路径,加速调试时的本地编译速度
|
||||
local_ip:=`echo "en0 eth0" | xargs -n1 ip addr show 2>/dev/null | grep inet | grep -v 127.0.0.1 | grep -v inet6 | tr "/" " " | awk '{print $$2}'`
|
||||
build-arg+=--build-arg local_url=http://$(local_ip)/dist-files
|
||||
build-arg+=--build-arg LOCAL_URL=http://$(local_ip)/dist-files
|
||||
|
||||
.PHONY: build clean clearclean upgrade
|
||||
|
||||
|
||||
@@ -4,54 +4,51 @@
|
||||
|
||||
**版本信息:**
|
||||
|
||||
- buster、latest
|
||||
- 10
|
||||
- latest
|
||||
- 11(bullseye)
|
||||
|
||||
**镜像信息:**
|
||||
|
||||
* 镜像地址:
|
||||
* 阿里云: registry.cn-shenzhen.aliyuncs.com/colovu/debian:buster
|
||||
* Docker Hub: colovu/debian:buster
|
||||
* 依赖镜像:debian:buster-slim
|
||||
* 阿里云(仅`amd64`): registry.cn-shenzhen.aliyuncs.com/colovu/debian:11
|
||||
* Docker Hub: colovu/debian:11
|
||||
* Colovu Registry: docker.colovu.com/colovu/debian:11
|
||||
* 依赖镜像:docker.io/library/debian:11-slim
|
||||
|
||||
> 后续相关命令行默认使用`[Docker Hub](https://hub.docker.com)`镜像服务器做说明
|
||||
> 后续相关命令行默认使用`[Colovu Registry](https://docker.colovu.com)`镜像服务器做说明
|
||||
|
||||
**与官方镜像差异:**
|
||||
|
||||
- 增加 `default、tencent、ustc、aliyun、huawei` 源配置文件,可在编译时通过 `ARG` 变量`apt_source`进行选择
|
||||
- 增加 `default、ustc、aliyun` 源配置文件,可在编译时通过 `ARG` 变量`APT_SOURCE`进行选择
|
||||
- 增加常用 Shell 脚本文件
|
||||
- 更新已安装的软件包
|
||||
- 增加`locales`,并设置默认编码格式为`en_US.utf8`
|
||||
- 增加`gosu`
|
||||
- 设置默认时区信息为 `Asia/Shanghai`
|
||||
- 默认增加 nss_wrapper 支持
|
||||
- 默认增加 curl 软件,用作镜像健康检查
|
||||
|
||||
|
||||
## TL;DR
|
||||
|
||||
Docker 快速启动命令:
|
||||
|
||||
```shell
|
||||
# 从 Docker Hub 服务器下载镜像并启动
|
||||
$ docker run -it colovu/debian /bin/bash
|
||||
# 从 Registry 服务器下载镜像并启动
|
||||
$ docker run -it docker.colovu.com/colovu/debian:11 /bin/bash
|
||||
```
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
## 使用说明
|
||||
|
||||
**下载镜像:**
|
||||
|
||||
```shell
|
||||
$ docker pull colovu/debian
|
||||
$ docker pull docker.colovu.com/colovu/debian:11
|
||||
```
|
||||
|
||||
- `colovu/debian:<TAG>`:镜像名称及版本标签
|
||||
- 不指定 TAG 时,默认下载 latest 镜像
|
||||
- 11:为镜像的 TAG,可针对性选择不同的 TAG 进行下载;可使用`latest`选择最新的镜像
|
||||
- 不指定 TAG 时,默认下载`latest`镜像
|
||||
|
||||
**查看镜像:**
|
||||
|
||||
@@ -62,12 +59,12 @@ $ docker images
|
||||
**命令行方式运行容器:**
|
||||
|
||||
```shell
|
||||
$ docker run -it --rm colovu/debian /bin/bash
|
||||
$ docker run -it --rm docker.colovu.com/colovu/debian:11 /bin/bash
|
||||
```
|
||||
|
||||
- `-it`:使用交互式终端启动容器
|
||||
- `--rm`:退出时删除容器
|
||||
- `colovu/debian:<TAG>`:镜像名称及版本标签;标签不指定时默认使用`latest`
|
||||
- `docker.colovu.com/colovu/debian:11`:镜像名称及版本标签
|
||||
- `/bin/bash`:在容器中执行`/bin/bash`命令;如果不执行命令,容器会在启动后立即结束并退出。
|
||||
|
||||
以该方式启动后,直接进入容器的命令行操作界面。如果需要退出,直接使用命令`exit`退出。
|
||||
@@ -75,16 +72,14 @@ $ docker run -it --rm colovu/debian /bin/bash
|
||||
**后台方式运行容器:**
|
||||
|
||||
```shell
|
||||
$ docker run -d --name test colovu/debian tail /dev/stderr
|
||||
$ docker run -d --name test docker.colovu.com/colovu/debian:11 tail /dev/stderr
|
||||
```
|
||||
|
||||
- `--name test`:命名容器为`test`
|
||||
- `-d`:以后台进程方式启动容器
|
||||
- `colovu/debian:<TAG>`:镜像名称及版本标签;标签不指定时默认使用`latest`
|
||||
- `docker.colovu.com/colovu/debian:11`:镜像名称及版本标签
|
||||
- `tail /dev/stderr`:在容器中执行`tail /dev/stderr`命令,以防止容器直接退出
|
||||
|
||||
|
||||
|
||||
以该方式启动后,如果想进入容器,可以使用以下命令:
|
||||
|
||||
```shell
|
||||
@@ -95,7 +90,6 @@ $ docker exec -it test /bin/bash
|
||||
- `test`:之前启动的容器名
|
||||
- `/bin/bash`:执行的命令
|
||||
|
||||
|
||||
## 配置修改
|
||||
|
||||
### 修改时区信息
|
||||
@@ -118,8 +112,6 @@ Local time is now: Tue Jul 21 09:16:14 UTC 2020.
|
||||
Universal Time is now: Tue Jul 21 09:16:14 UTC 2020.
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 修改字符编码格式
|
||||
|
||||
可在生成镜像时或容器初始化 Shell 脚本中,使用以下命令:
|
||||
@@ -136,13 +128,10 @@ $ export LC_ALL=zh_CN.UTF-8 LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8
|
||||
|
||||
更新成功后,可使用`locale`命令查看字符编码信息。
|
||||
|
||||
|
||||
## 更新记录
|
||||
|
||||
- buster、latest
|
||||
+ 删除应用程序 gosu 及 tini
|
||||
- 10
|
||||
|
||||
- latest
|
||||
- 11、bullseye
|
||||
|
||||
----
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
|
||||
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
|
||||
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
|
||||
deb http://mirrors.aliyun.com/debian-security buster/updates main
|
||||
|
||||
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
|
||||
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
|
||||
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
|
||||
deb-src http://mirrors.aliyun.com/debian-security buster/updates main
|
||||
deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
|
||||
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
|
||||
deb http://mirrors.aliyun.com/debian-security bullseye/updates main
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
# deb http://snapshot.debian.org/archive/debian/20200607T000000Z buster main
|
||||
deb http://deb.debian.org/debian buster main
|
||||
# deb http://snapshot.debian.org/archive/debian-security/20200607T000000Z buster/updates main
|
||||
deb http://security.debian.org/debian-security buster/updates main
|
||||
# deb http://snapshot.debian.org/archive/debian/20200607T000000Z buster-updates main
|
||||
deb http://deb.debian.org/debian buster-updates main
|
||||
deb http://deb.debian.org/debian bullseye main
|
||||
deb http://security.debian.org/debian-security bullseye/updates main
|
||||
deb http://deb.debian.org/debian bullseye-updates main
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
deb http://mirrors.huaweicloud.com/debian/ buster main contrib non-free
|
||||
deb http://mirrors.huaweicloud.com/debian/ buster-updates main contrib non-free
|
||||
deb http://mirrors.huaweicloud.com/debian/ buster-backports main contrib non-free
|
||||
deb http://mirrors.huaweicloud.com/debian-security/ buster/updates main contrib non-free
|
||||
|
||||
deb-src http://mirrors.huaweicloud.com/debian/ buster main contrib non-free
|
||||
deb-src http://mirrors.huaweicloud.com/debian/ buster-updates main contrib non-free
|
||||
deb-src http://mirrors.huaweicloud.com/debian/ buster-backports main contrib non-free
|
||||
@@ -1,9 +0,0 @@
|
||||
deb http://mirrors.cloud.tencent.com/debian/ buster main non-free contrib
|
||||
deb http://mirrors.cloud.tencent.com/debian/ buster-updates main non-free contrib
|
||||
deb http://mirrors.cloud.tencent.com/debian/ buster-backports main non-free contrib
|
||||
deb http://mirrors.cloud.tencent.com/debian-security buster/updates main
|
||||
|
||||
deb-src http://mirrors.cloud.tencent.com/debian/ buster main non-free contrib
|
||||
deb-src http://mirrors.cloud.tencent.com/debian/ buster-updates main non-free contrib
|
||||
deb-src http://mirrors.cloud.tencent.com/debian/ buster-backports main non-free contrib
|
||||
deb-src http://mirrors.cloud.tencent.com/debian-security buster/updates main
|
||||
@@ -1,9 +1,3 @@
|
||||
deb http://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
|
||||
deb http://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
|
||||
deb http://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free
|
||||
deb http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
|
||||
|
||||
deb-src http://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
|
||||
deb-src http://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
|
||||
deb-src http://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free
|
||||
deb-src http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
|
||||
deb http://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
|
||||
deb http://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
|
||||
deb http://mirrors.ustc.edu.cn/debian-security/ bullseye/updates main contrib non-free
|
||||
|
||||
Reference in New Issue
Block a user