So… I trying start learning Docker. But I can’t sync the host and the container using volumes on change and save code (using the npm run dev). All the time I have to restart the docker-compose up --build
to the "sync" kick in, but after this any change don’t update the folder or code. My exemple code:
install Next.js typescript as base.
npx create-next-app@latest --ts
Docker-compose:
version: "3"
services:
node-myname:
build:
context: .
dockerfile: DockerFile.dev
ports:
- "3000:3000"
command: "npm run dev"
restart: always
volumes:
- .:/usr/src/home/node/app/
DockerFile:
FROM node:16
WORKDIR /home/node/app
COPY . .
RUN npm install
The recomended is using volumes insted bind…
I can’t find a workaround.
2
Answers
After total reinstall Docker Windows (using Revo uninstaller)... the sync is working (i can create a file .txt and this is show on docker exec)! But, after that the hot reaload using
dev
don't work on Docker. I solve this using another StackOverflow post: Solution Docker Hot Reload Install on the next.config.js.Another thing... if i copy all the stuff from Nextjs host to the Docker container the Sync go way again... so... I can only copy
COPY package.json ./
from host.next.config.js:
Dockerfile:
docker-compose:
and all finaly work as intended. I don't know why... but if i try the same path as before i get a error... but all work now!
Git Hub Final Code
May be you need to use same path?!
UPD: Checkout: https://github.com/theanurin/stackoverflow.68511005 and see INITLOG.md with steps "how to setup the project"