Skip to content

Instantly share code, notes, and snippets.

@garry-jeromson
Created September 6, 2022 09:33
Show Gist options
  • Save garry-jeromson/1ef2163dd85e6433fe6b3f71f3c887a3 to your computer and use it in GitHub Desktop.
Save garry-jeromson/1ef2163dd85e6433fe6b3f71f3c887a3 to your computer and use it in GitHub Desktop.
Docker compose config with node_modules volume mount
version: '3.5'
services:
web:
user: ${TEST_USER}
image: migrosonline/some-component:develop
build:
target: develop
environment:
NODE_ENV: development
ENVIRONMENT: local
JEST_JUNIT_OUTPUT_DIR: "/srv/app/test_reports/junit"
volumes:
- ./app:/srv/app
# Mount a named volume to the node_modules folder. This is a workaround to ensure that we never accidentally
# mount our local node_modules volume in the container; it allows us to develop both inside and outside of the
# container without having to worry about conflict (e.g. macOS vs Linux node dependencies). We use a named
# volume rather than an anonymous volume so we can easily identify the volume, and so that multiple anonymous
# volumes don't clog up our hard drives.
- node_modules:/srv/app/node_modules:delegated
networks:
- no-internet
command: npm run test
volumes:
node_modules:
networks:
no-internet:
driver: bridge
internal: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment