Linux users aren't immune from trouble either. Host volume permissions are a big source of pain--if your mounted files don't have the same UID/GUID as the user baked into the dockerfile then you'll hose access to the files on your local machine. Most simple dockerfiles run as root (especially dockerfiles created by windows or mac developers who never deal with this problem) and all the created files inside them show up as root owned on your localhost. You have to take special care to craft your dockerfile to not run as a root user, launch with explicit user UID/GUID that matches your host machine, and use a tool like fixuid as an entrypoint to fix up mismatches.
A good workaround though is to use docker's internal volumes instead of host mounts. This fixes all the Linux permission issues (the internal volumes live in their own root/docker managed location), and fixes the slowness on other platforms (no VM folder mount slowdown). But you give up the freedom of seeing your files locally and need to go all in with something like VS code remote containers, or running your IDE directly in the container.
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>> I'm never confident in the changes I make, but my style is to write a few lines at a time, save, re-run or refresh.
This is a pretty typical frontend development pattern, especially seeing "refresh."
As a backend dev working in statically typed languages, I will sometimes code for hours without running, and I wouldn't say anything about it is terrible. I haven't worked with Typescript, but it wouldn't surprise me if it enabled a similar development process.
I wouldn't necessarily infrequent running as a technique worth emulating, but in certain situations it works pretty well.
Maybe I'm doing things wrong, but docker volumes are essential in how I like to dev.
Maybe it's because I'm never confident in the changes I make, but my style is to write a few lines at a time, save, re-run or refresh. I can't imagine having to do a docker build every code change. If you do the later, it's just nominally better than developing on a remote server, which brings its own challenges.