docker经常需要挂载文件到容器中,比如启动nginx

# docker run -d --name test_nginx -v /tmp/nginx.conf:/etc/nginx/nginx.conf nginx

然后就有修改配置文件然后刷新的功能,如果直接用vi编辑宿主机文件

# vi /tmp/nginx.conf

然后在docker容器中执行reload

# docker exec -it test_nginx nginx -s reload

会发现配置没有生效,此时直接查看docker容器中的文件内容发现还是旧的

# docker exec -it test_nginx cat /etc/nginx/nginx.conf

所以看起来只能将docker容器restart,正确的操作方法应该是

# cp /tmp/nginx.conf /tmp/nginx.conf2
# vi /tmp/nginx.conf2
# cat /tmp/nginx.conf2 > /tmp/nginx.conf
# docker exec -it test_nginx nginx -s reload

这是因为用vi编辑保存时会修改文件的inode,而cat重定向不会,查看文件inode的方法

# stat /path/to/file
# ls -i /path/to/file

 

相关文章:

  • 2022-02-24
  • 2021-09-26
  • 2021-07-18
  • 2021-10-12
  • 2021-12-28
  • 2021-12-14
  • 2021-08-02
  • 2021-12-01
猜你喜欢
  • 2021-07-27
  • 2021-12-16
  • 2022-01-02
  • 2021-06-06
  • 2021-09-01
  • 2022-02-09
  • 2022-02-28
相关资源
相似解决方案