Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit 7c9b6ce

Browse files
committed
docs(docker): alpine镜像源配置
1 parent 4d2e03b commit 7c9b6ce

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
# [alpine]源配置
3+
4+
## 问题
5+
6+
默认`alpine`源地址可通过`/etc/apk/repositories`文件查看
7+
8+
```
9+
$ docker run -it alpine
10+
/ # cd /etc/apk/
11+
/etc/apk # pwd
12+
/etc/apk
13+
/etc/apk # ls
14+
arch keys protected_paths.d repositories world
15+
/etc/apk #
16+
/etc/apk # cat repositories
17+
http://dl-cdn.alpinelinux.org/alpine/v3.11/main
18+
http://dl-cdn.alpinelinux.org/alpine/v3.11/community
19+
```
20+
21+
使用默认源无法下载应用,以`NodeJS`为例
22+
23+
```
24+
/etc/apk # apk add nodejs
25+
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
26+
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.11/main: temporary error (try again later)
27+
WARNING: Ignoring APKINDEX.70f61090.tar.gz: No such file or directory
28+
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
29+
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.11/community: temporary error (try again later)
30+
WARNING: Ignoring APKINDEX.ca2fea5b.tar.gz: No such file or directory
31+
ERROR: unsatisfiable constraints:
32+
nodejs (missing):
33+
required by: world[nodejs]
34+
```
35+
36+
## 解析
37+
38+
参考[Alpine Linux 源使用帮助](https://mirrors.ustc.edu.cn/help/alpine.html),替换成国内镜像源
39+
40+
```
41+
/etc/apk # sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
42+
/etc/apk #
43+
/etc/apk # cat repositories
44+
http://mirrors.ustc.edu.cn/alpine/v3.11/main
45+
http://mirrors.ustc.edu.cn/alpine/v3.11/community
46+
```
47+
48+
配置`NodeJS`环境如下
49+
50+
```
51+
/etc/apk # apk add nodejs
52+
fetch http://mirrors.ustc.edu.cn/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
53+
fetch http://mirrors.ustc.edu.cn/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
54+
(1/7) Installing ca-certificates (20191127-r1)
55+
(2/7) Installing c-ares (1.15.0-r0)
56+
(3/7) Installing libgcc (9.2.0-r3)
57+
(4/7) Installing nghttp2-libs (1.40.0-r0)
58+
(5/7) Installing libstdc++ (9.2.0-r3)
59+
(6/7) Installing libuv (1.34.0-r0)
60+
(7/7) Installing nodejs (12.15.0-r1)
61+
Executing busybox-1.31.1-r9.trigger
62+
Executing ca-certificates-20191127-r1.trigger
63+
OK: 36 MiB in 21 packages
64+
/etc/apk #
65+
/etc/apk # apk add npm
66+
(1/1) Installing npm (12.15.0-r1)
67+
Executing busybox-1.31.1-r9.trigger
68+
OK: 64 MiB in 22 packages
69+
```
70+
71+
## dockerfile
72+
73+
编写一个`Dockerfile`脚本,实现镜像源替换
74+
75+
```
76+
FROM alpine:latest
77+
LABEL maintainer "zhujian <zjzstu@github.com>"
78+
79+
RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
80+
```
81+
82+
### 构建
83+
84+
```
85+
$ docker build -t zjzstu/alpine:latest .
86+
Sending build context to Docker daemon 2.048kB
87+
Step 1/3 : FROM alpine:latest
88+
---> e7d92cdc71fe
89+
Step 2/3 : LABEL maintainer "zhujian <zjzstu@github.com>"
90+
---> Running in e887d20623cd
91+
Removing intermediate container e887d20623cd
92+
---> 260632029e45
93+
Step 3/3 : RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
94+
---> Running in 0481eecdd0e9
95+
+ sed -i s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g /etc/apk/repositories
96+
Removing intermediate container 0481eecdd0e9
97+
---> 6c891a208c35
98+
Successfully built 6c891a208c35
99+
```
100+
101+
### 运行
102+
103+
```
104+
$ docker run -it zjzstu/alpine
105+
/ # node
106+
/bin/sh: node: not found
107+
/ # apk add nodejs
108+
fetch http://mirrors.ustc.edu.cn/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
109+
fetch http://mirrors.ustc.edu.cn/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
110+
(1/7) Installing ca-certificates (20191127-r1)
111+
(2/7) Installing c-ares (1.15.0-r0)
112+
(3/7) Installing libgcc (9.2.0-r3)
113+
(4/7) Installing nghttp2-libs (1.40.0-r0)
114+
(5/7) Installing libstdc++ (9.2.0-r3)
115+
(6/7) Installing libuv (1.34.0-r0)
116+
(7/7) Installing nodejs (12.15.0-r1)
117+
Executing busybox-1.31.1-r9.trigger
118+
Executing ca-certificates-20191127-r1.trigger
119+
OK: 36 MiB in 21 packages
120+
/ #
121+
/ # node -v
122+
v12.15.0
123+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ nav:
5050
- '[docker search]搜索镜像': './docker/advanced/[docker search]搜索镜像.md'
5151
- '[Docker][SSH]远程登录Ubuntu': './docker/advanced/[Docker][SSH]远程登录Ubuntu.md'
5252
- '[Ubuntu]nvidia-docker安装': './docker/advanced/[Ubuntu]nvidia-docker安装.md'
53+
- '[alpine]源配置': './docker/advanced/[alpine]源配置.md'
5354
- Dockerfile:
5455
- 'Dockerfile编写': './docker/dockerfile/Dockerfile编写.md'
5556
- 'FROM': './docker/dockerfile/FROM.md'

0 commit comments

Comments
 (0)