Docker:卷中的文件未在目标中更新 [英] Docker: Files from volume not updated in target

查看:66
本文介绍了Docker:卷中的文件未在目标中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,并且已经使用此Dockerfile创建了一个映像:

I'm newbie in Docker and I have created an image with this Dockerfile:

FROM node:8.12.0
LABEL version="1.0"
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD ["node", "index.js"]

我运行图像,它可以正常工作.但是,如果在主机目录中更新index.js时使用WORKDIR运行图像映射主机目录,则此更新不会传播到WORKDIR中.

I run the image and it works. But If I run the image mapping host directory with WORKDIR when I update index.js in host directory this updating is not propagated into WORKDIR.

我使用以下命令运行图像:

I run the image with this command:

docker run --name basketmetrics -v /home/josecarlos/Workspace/nodejs/basketmetrics2:/usr/src/app -p 8080:8080 -d basketmetrics2/node-app:1.0

这是我的主机目录/home/josecarlos/Workspace/nodejs/basketmetrics2

This is my host directory /home/josecarlos/Workspace/nodejs/basketmetrics2

这是容器/usr/src/app中的目标目录.如果检查容器,可以看到主机目录已与WORKDIR映射

And this is the target directory in the container /usr/src/app. If I inspect the container I can see that the host directory is mapped with the WORKDIR

我做错了什么?

更新我:

我已停止容器并在主机目录中修改了文件index.js.如果我再次运行该图像,则可以看到内容已更新!!!

I have stoped my container and modify the file index.js in my host directory. If I run again the image, then I can see the content updated!!!

为什么我的内容没有即时更新?

Why my content is not updated on the fly?

推荐答案

看起来像已知问题.链接

如果您使用的是诸如vim之类的编辑器,则在保存文件时会不直接保存文件,而是创建一个新文件并复制它到位.这会中断基于inode的绑定安装.自从保存文件有效地更改了索引节点,更改不会传播到容器中.重新启动容器后,新的索引节点.如果您在适当位置编辑文件,则应该看到更改正在传播.

If you are using some editor like vim, when you save the file it does not save the file directly, rather it creates a new file and copies it into place. This breaks the bind-mount, which is based on inode. Since saving the file effectively changes the inode, changes will not propagate into the container. When the container is restarted the new inode. If you edit the file in place you should see changes propagate.

这是文件安装的已知限制,无法修复.

进一步的注释中,您可以找到针对各种编辑器的一些解决方法.检查是否有效果

Further in comments you can find some workarounds for various editors. Check if any works

这篇关于Docker:卷中的文件未在目标中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆