Docker: Files from volume not updated in target

旧巷老猫 提交于 2021-01-27 07:01:05

问题


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"]

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

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

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

What am I doing wrong?

Update I:

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?


回答1:


Looks like known issue. 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.

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



来源:https://stackoverflow.com/questions/52897000/docker-files-from-volume-not-updated-in-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!