Docker容器如何修改/etc/hosts文件
docker吧
全部回复
仅看楼主
level 1
我商天1Q 楼主
最近在项目中使用到Docker,我需要动态修改Docker容器内的主机映射,但在使用sed命令修改/etc/hosts文件时候出现错误:sed: cannot rename /etc/sed8DbrGm: Device or resource busy,请问一下大家对于这个问题有没有什么比较简单快捷的方法解决呢?
2016年01月11日 08点01分 1
level 1
我商天1Q 楼主
问题已经解决,解决方案如下:
在Docker运行时启动的脚本中把原来的/etc/hosts复制一份到/etc/hosts.temp中,既然原来的文件不能修改,则修改复制后的文件,然后可以使用cat命令cat/etc/hosts.temp > /etc/hosts覆盖,可行!
2016年01月13日 02点01分 2
mark
2016年10月22日 04点10分
level 3
这也是我想知道的,感谢分享
2016年01月19日 11点01分 3
level 1
我发现了另外一种方式:
docker exec 1ebea17823f3 /bin/sh -c "echo test >> /etc/hosts"
参见:https://github.com/moby/moby/issues/15604?_pjax=%23js-repo-pjax-container
2017年08月14日 07点08分 4
level 3
docker.site[大拇指]
2017年08月20日 13点08分 5
level 1
最近刚好遇到这个问题,解决方法附上:http://blog.realjf.com/archives/62
2017年12月26日 13点12分 6
1