-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile-base
More file actions
71 lines (61 loc) · 2.74 KB
/
Dockerfile-base
File metadata and controls
71 lines (61 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# 国内镜像(Ubuntu 24.04 默认使用 deb822:/etc/apt/sources.list.d/ubuntu.sources)
ARG UBUNTU_MIRROR_HOST=mirrors.aliyun.com
ARG UBUNTU_CODENAME=noble
# 不依赖“原文件包含某些URL字符串”的替换:直接禁用原源并写入国内源
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
mirror_path="ubuntu"; \
case "$arch" in \
arm64|armhf|armel) mirror_path="ubuntu-ports" ;; \
esac; \
mirror_uri="http://${UBUNTU_MIRROR_HOST}/${mirror_path}/"; \
# Ubuntu 24.04 常见为 deb822 源:禁用它,避免仍然走默认海外源
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then \
mv /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak; \
fi; \
# 你已确认 /etc/apt/sources.list 里没配置国内镜像:这里直接追加国内镜像源即可
if [ -f /etc/apt/sources.list ]; then \
sed -i \
-e 's/^[[:space:]]*deb[[:space:]]\+/# deb /' \
-e 's/^[[:space:]]*deb-src[[:space:]]\+/# deb-src /' \
/etc/apt/sources.list; \
else \
touch /etc/apt/sources.list; \
fi; \
printf '%s\n' \
"deb ${mirror_uri} ${UBUNTU_CODENAME} main restricted universe multiverse" \
"deb ${mirror_uri} ${UBUNTU_CODENAME}-updates main restricted universe multiverse" \
"deb ${mirror_uri} ${UBUNTU_CODENAME}-backports main restricted universe multiverse" \
"deb ${mirror_uri} ${UBUNTU_CODENAME}-security main restricted universe multiverse" \
>> /etc/apt/sources.list; \
apt-get update; \
apt-get upgrade -y
# 安装基本工具:git, curl, wget, vim, net-tools (包含netstat), iputils-ping (包含ping)等,用于问题排查
RUN set -eux; \
apt-get install -y --no-install-recommends \
ca-certificates \
git curl wget vim \
net-tools iputils-ping \
python3 python3-pip \
openssh-client \
gnupg; \
rm -rf /var/lib/apt/lists/*
# 安装Node.js 22(使用NodeSource仓库)
RUN set -eux; \
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -; \
apt-get install -y --no-install-recommends nodejs; \
rm -rf /var/lib/apt/lists/*
# npm 国内源
RUN npm config set registry https://registry.npmmirror.com
# pip/uv 国内源(对 pip/uv 生效)
ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ \
PIP_TRUSTED_HOST=mirrors.aliyun.com \
UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
# 安装uv(使用pip安装,避免curl下载脚本的潜在网络问题)
RUN pip3 install uv --break-system-packages
# 设置工作目录(可选,根据需要)
WORKDIR /app
# 清理apt缓存,减小镜像大小
RUN apt-get clean && rm -rf /var/lib/apt/lists/*