News for hackers. Stuff that matters.
Re:You Don't Need to Rebuild Your Development Docker Image o... by krono on Monday May 31, 2021 @01:28PM (#27346332)
How awesome would it be if we could exclude specific dirs or files from bind mounts. Think of cache directories, log files, and, of course, node_modules.

The common workaround to this, is to create an empty volume and map whatever you don't want mounted to it. You'll end up with an empty directory in your host system, but its contents are available from within the container.

It has many problems though, mostly permission and ownership related, but it somehow makes Docker for Mac even slower and crash even more often than usual.

Example minimal docker-compose.yaml file for a custom "devcontainer" we use in VSCode that showcases the workaround:

  version: '3.8'

  services:
    project:
      image: devcontainer:dev
      container_name: devcontainer
      build:
        context: .
        dockerfile: Dockerfile
        args:
          ALPINE_VERSION: '3.13'
          NODE_VERSION: '14.16.1'
      ports:
        - 3000:3000
      volumes:
        - ..:/project
        - node_modules:/project/node_modules:cached

  volumes:
    node_modules:

This feature gets asked for quite often. Here are two issues on GitHub I was quickly able to find: https://github.com/docker/compose/issues/6470 https://github.com/docker/compose/issues/6997
Re:You Don't Need to Rebuild Your Development Docker Image o... by sm4rk0 on Monday May 31, 2021 @02:47PM (#27347010)
@bdcravens mentioned this as a solution in another comment:

http://docker-sync.io/

Re:You Don't Need to Rebuild Your Development Docker Image o... by krono on Tuesday June 01, 2021 @12:44PM (#27357411)
Thanks! I came across that project in the past, bookmarked it, and then completely forgot it even existed. Trying it out tonight :)