alpine image中/etc/hosts那些事

遇到此问题是因为在项目中在Docker image中对一句命令RUN echo "hosts: files dns" >> /etc/nsswitch.conf不理解,因此记录下在查找过程中学到的内容。
首先alpine镜像中默认缺少nsswitch.conf文件,需要在镜像添加此文件并且写入hosts: files dns对/etc/hosts的修改才能生效。为什么要这样做呢,因为在Golang的net包的源码net/conf.go中,在 alpine 中/etc/nsswitch.conf 不存在,导致了先从 dns 查询,然后 file 查询,如果在alpine中设置了nsswitch.conf,golang程序会先从file文件查询,然后从dns查询。

你可能感兴趣的:(alpine image中/etc/hosts那些事)