1. Execute error reporting
Execute docker build -t image:version -f Dockerfile .
Error:
2. Check online solutions
Online documentation solutions:
Here I made a change to write these into the dockerfile
Added a few RUN
RUN rm -rf /var/cache/apk RUN mkdir -p /var/cache/apk RUN apk update -v
Found still reported the same error
3. My troubleshooting
3.1. Directly enter the underlying image
# 拉去镜像并进入容器 docker pull alpine:latest docker exec -it alpine:latest bash # 手动测试 apk update -v # 测试失败 # 再次测试 rm -rf /var/cache/apk mkdir -p /var/cache/apk apk update -v # 还是失败 ## 突然想到这边用的默认镜像那么yum源就是网络yum源,尝试测试网络 ping www.baidu.com # 发现网络不通 exit # 退出
3.2. Add network test
docker run -it --net=host alpine:latest bash
4. Add network (--network=host) when docker build
docker build -t alpine:latest -f Dockerfile . --network=host