colima
colima copied to clipboard
NodeJS hot reload issue
Hello,
I switched from Docker Desktop to Colima. I noticed an issue with "watcher" on bind volume. I created a repository: https://github.com/shenron/colima-hot-reload-issue
The container is not able to see when a file has been updated. But if I touch the file from the container it works. I guess it's linked to the volume.
I'm using the Macbook Pro M1 Max with:
colima version 0.3.4
git commit: 5a4a70481ca8d1e794677f22524e3c1b79a9b4ae
runtime: docker
arch: aarch64
client: v20.10.14
server: v20.10.11
limactl version 0.9.2
The way colima binds host directories into the guest VM means that certain filesystem events are not observed / generated.
You can work around this by using --legacy-watch
in nodemon
that will fall back to polling instead of the fsevents integration.
Hello, thank you for your answer.
The legacy is a workaround, but unfortunately in my use case it's very slow and use a lot of cpu. It's not the best, but for now when I finished to edit my code I "touch" the entrypoint of the application.
docker exec -ti $CONTAINER_ID touch /usr/src/app/src/index.ts
I'm facing the same issue with ts-node-dev
. Is this an issue that will eventually be solved by colima or we will never receive the same events when using colima?
Is this an issue that will eventually be solved by colima or we will never receive the same events when using colima?
I am working on a workaround taking a similar approach to https://github.com/abiosoft/colima/issues/261#issuecomment-1116466858 while leveraging inotify.
I paused due to some issues with the Go library at the time, but I will revisit it.
Is this an issue that will eventually be solved by colima or we will never receive the same events when using colima?
I am working on a workaround taking a similar approach to #261 (comment) while leveraging inotify.
I paused due to some issues with the Go library at the time, but I will revisit it.
It would be great to have this feature completed. Is there a work-in-progress branch that I could possibly help continue/test?
Hi, is there any progress on that? If you need some help, I may push our development team to help you. We need this so our frontend team could work using colima. Docker for mac is not an option for us)
@djirik support for virtiofs mounts is imminent and would be part of the next release.
It has been merged into master upstream in Lima and currently being integrated and tested in Colima, the early results have been quite impressive.
Virtiofs is same tech used by Docker Desktop for the fast volume speeds.
@abiosoft thank you very much
@abiosoft Hi, do you have an idea when would it be available?
@djirik within the next week or two https://github.com/abiosoft/colima/issues/497#issuecomment-1345257182.
You can actually test it now ~~if you can build Colima from source (and brew install --HEAD lima
), it's on the support-vz
branch~~.
brew install --HEAD colima
@abiosoft hi again, I've succesfully switched to virtiofs on macOs 13. However nodemon
still does not see updated files.
colima status
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
INFO[0000] mountType: virtiofs
INFO[0000] socket: unix:///Users/hacker/.colima/default/docker.sock
--legacy-watch
for nodemon
doesn't seem to be helping at all.
btw we are using nuxt
framework, maybe it is something related with it?
@abiosoft hi again, I've succesfully switched to virtiofs on macOs 13. However nodemon still does not see updated files.
@djirik hmmm 🤔 did you reset. i.e. colima delete && colima start
?
Is your project something that I can try to reproduce? I have tested with a number of development environments that provides live reload and it has worked fine.
@djirik also, kindly confirm lima --version
is v0.14.0
?
@abiosoft yes, I have reset it. Unfortunately, I can not share source code, as it is under NDA.
limactl version 0.14.0
I can ask frontend team if they can make sample project without production code.
@abiosoft I have recreated colima again just to be sure, seems like it changed things a bit, now I'm having a lot of permission/access rights errors, I will fix it and return with more feedback.
@abiosoft File permissions are hell with virtiofs. I can't even launch node project with volume mounts. Can not figure out how to set user:group in compose file.
@abiosoft File permissions are hell with virtiofs. I can't even launch node project with volume mounts. Can not figure out how to set user:group in compose file.
Do you have an idea of the userId in the container? You can check by running id -u
in the container.
What docker image are you using?
version: '3.9'
services:
nuxt:
build:
dockerfile: ../docker/nuxt/Dockerfile
context: ./source
target: node_base
image: ${NUXT_IMAGE_NAME:-localhost/nuxt}:${NUXT_IMAGE_TAG:-latest}
# user: $DEV_LOCAL_UID:$DEV_LOCAL_GID # here I've tried 501:20, 1000:1000, 501:1000, 0:0
restart: 'no'
environment:
FORCE_COLOR: '1'
NPM_TOKEN: $NPM_TOKEN
entrypoint: sh
command:
- -xec
- |-
npm run npm-auth-repo --loglevel verbose
npm install --loglevel verbose
npm run dev --loglevel verbose
volumes:
- ./source:/app
- ./volumes/nuxt/HOME:/home/node
FROM node:16.17.1-alpine AS node_base
WORKDIR /app
ENV HOST 0.0.0.0
EXPOSE 3000
Everytime I'm getting either 243 error from node, or permission denied for creating files in ./volumes/nuxt/HOME
.
I've also tried chmod +rwx
on HOME
dir without effect.
@djirik as an unrecommended stopgap, the permission denied error should go away if you run chmod -R 777 ./volumes/nuxt/HOME
.
Give me a moment, let me try to reproduce your error using the node:16.17.1-alpine
image.
@djirik out of curiosity, why is /home/node
getting mounted?
@abiosoft I've tried with 777, but it didn't have any effect. Yes, /home/node
is mounted. .npm
dir is created and after that it says permission denied)
@djirik I am unable to reproduce your permission issues. You can send me an email at the email on my GitHub profile and we can schedule a session to troubleshoot this.
As for the hot reload issue, I can confirm it is not yet fixed with virtiofs. Apparently, I was testing with a dotnet project and it works fine, and thereby assumed it catered for all other environments (including the node stack) as well.
I can confirm that also on my nodejs project mounted volumes are not "touched" in the container. I encounter no permission issues though.
- I resetted colima with
colima delete && colima start
-
lima --version
=> limactl version 0.14.1
@codingluke what is your node version? can you please share you Dockerfile and docker-compose?
@abiosoft I have sent you an email
@djirik I use the latest 18.12.1. It is a docusaurus/marp project.
- Dockerfile
-
docker-compose.yaml
- About the permission, I added a
user: root
. This was somehow needed before. When I delete it now it works too!
- About the permission, I added a
- package.json
@codingluke I get it now, you are not mounting sources and NODE_HOME into container, this is why you don't have permission issues I guess.
correct and I would recommend to only mount the part which is edited locally. I don't see the need to share node_modules and co. For persistence I would use docker volumes. Of course there might be some reason to do it differently.
@abiosoft I have skipped mounting /home/node, as it was found unnecessary, but hot reload is still not working :(.
The working behavior is like this:
- update file
-
touch
file incolima ssh
- refresh is triggered.
Can we steal something from Docker Desktop
, so it would work?
I assumed virtiofs will enable hot reload out of the box. Since that has now turned out not to be the case, this would be resumed https://github.com/abiosoft/colima/issues/261#issuecomment-1219565057.