Skip to content

Commit 5d91c5a

Browse files
committed
replace ip.cn
Signed-off-by: Kang Huaishuai <[email protected]>
1 parent 4878552 commit 5d91c5a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

.github/workflows/check-link.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ jobs:
5959
"x.x.x.x/base",\
6060
"x.x.x.x:9000/minio/",\
6161
"https://www.freedesktop.org/wiki/Software/systemd/",\
62-
"ip.cn",\
6362
"www.aliyun.com" \
6463
--allow-dupe \
6564
--skip-save-results \

image/dockerfile/entrypoint.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FROM ubuntu:18.04
2121
RUN apt-get update \
2222
&& apt-get install -y curl \
2323
&& rm -rf /var/lib/apt/lists/*
24-
CMD [ "curl", "-s", "http://ip.cn" ]
24+
CMD [ "curl", "-s", "http://myip.ipip.net" ]
2525
```
2626

2727
假如我们使用 `docker build -t myip .` 来构建镜像的话,如果我们需要查询当前公网 IP,只需要执行:
@@ -38,12 +38,12 @@ $ docker run myip -i
3838
docker: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"-i\\\": executable file not found in $PATH\"\n".
3939
```
4040

41-
我们可以看到可执行文件找不到的报错,`executable file not found`。之前我们说过,跟在镜像名后面的是 `command`,运行时会替换 `CMD` 的默认值。因此这里的 `-i` 替换了原来的 `CMD`,而不是添加在原来的 `curl -s http://ip.cn` 后面。而 `-i` 根本不是命令,所以自然找不到。
41+
我们可以看到可执行文件找不到的报错,`executable file not found`。之前我们说过,跟在镜像名后面的是 `command`,运行时会替换 `CMD` 的默认值。因此这里的 `-i` 替换了原来的 `CMD`,而不是添加在原来的 `curl -s http://myip.ipip.net` 后面。而 `-i` 根本不是命令,所以自然找不到。
4242

4343
那么如果我们希望加入 `-i` 这参数,我们就必须重新完整的输入这个命令:
4444

4545
```bash
46-
$ docker run myip curl -s http://ip.cn -i
46+
$ docker run myip curl -s http://myip.ipip.net -i
4747
```
4848

4949
这显然不是很好的解决方案,而使用 `ENTRYPOINT` 就可以解决这个问题。现在我们重新用 `ENTRYPOINT` 来实现这个镜像:
@@ -53,7 +53,7 @@ FROM ubuntu:18.04
5353
RUN apt-get update \
5454
&& apt-get install -y curl \
5555
&& rm -rf /var/lib/apt/lists/*
56-
ENTRYPOINT [ "curl", "-s", "http://ip.cn" ]
56+
ENTRYPOINT [ "curl", "-s", "http://myip.ipip.net" ]
5757
```
5858

5959
这次我们再来尝试直接使用 `docker run myip -i`
@@ -109,8 +109,8 @@ CMD [ "redis-server" ]
109109
...
110110
# allow the container to be started with `--user`
111111
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
112-
chown -R redis .
113-
exec su-exec redis "$0" "$@"
112+
find . \! -user redis -exec chown redis '{}' +
113+
exec gosu redis "$0" "$@"
114114
fi
115115

116116
exec "$@"

0 commit comments

Comments
 (0)