With below preset:
version: "3.5"
services:
FronServer:
image: node:16-alpine
container_name: Example-Production-FrontServer
working_dir: /var/www/example.com
volumes:
- .:/var/www/example.com
- FrontServerDependencies:/var/www/example.com/node_modules:nocopy
command: sh -c "echo 'Installing dependencies ...' \
&& npm install --no-package-lock \
&& node FrontServerEntryPoint.js --environment production"
ports: [ "8080:8080" ]
environment:
- DATABASE_HOST=Database
depends_on: [ Database ]
Database:
image: postgres
container_name: Example-Production-Database
ports: [ "5432:5432" ]
environment:
- POSTGRES_PASSWORD=pass1234
volumes:
- DatabaseData:/data/example.com
volumes:
FrontServerDependencies: { driver: "local" }
DatabaseData: {}
the launching of the docker-compose causes the empty node_modules directory on local machine:
How to make it not appear on host machine without additional Dockerfile?
In my case, I need the installed node_modules lost after container has been stopped. Maybe tmpfs is what I need but have not found the example suited with my case.
Please note that package.json included to production build directory is not even with the package.json of the source code: there are many dependencies which are requires only at local development stage, and also front-end dependencies has been pre-bundled (with copyright comments, of course) - no need to install them anymore.