Docker:卷中的文件未在目标中更新
Docker: Files from volume not updated in target
我是 Docker 的新手,我用这个 Docker 文件创建了一个图像:
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。
我运行这个命令的图像:
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
这是容器中的目标目录/usr/src/app。如果我检查容器,我可以看到主机目录映射到 WORKDIR
我做错了什么?
更新一:
我已经停止了容器并修改了主机目录中的文件 index.js。如果我运行再刷一次图片,我就能看到内容更新了!!!
为什么我的内容没有即时更新?
看起来像是已知问题。 Link
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.
This is a known limitation of file-mounts and is not fixable.
您还可以在评论中找到适用于各种编辑器的一些解决方法。检查是否有效
我是 Docker 的新手,我用这个 Docker 文件创建了一个图像:
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。
我运行这个命令的图像:
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
这是容器中的目标目录/usr/src/app。如果我检查容器,我可以看到主机目录映射到 WORKDIR
我做错了什么?
更新一:
我已经停止了容器并修改了主机目录中的文件 index.js。如果我运行再刷一次图片,我就能看到内容更新了!!!
为什么我的内容没有即时更新?
看起来像是已知问题。 Link
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.
This is a known limitation of file-mounts and is not fixable.
您还可以在评论中找到适用于各种编辑器的一些解决方法。检查是否有效