I am using a docker and mounting something into the /home/(user) directory on the docker image using
-v ~/.aws:/home/$(shell id -nu)/.aws. The issue is, since /home/(user) did not exist prior to creating the docker, /home/(user) ends up being owned by root. This is causing issues for pip, sam-cli, etc because they are all attempting to store some information in the user home directory.
How can I avoid this situation without completely abandoning using a specific user? I've tried using chown to change the ownership, but I always get 'Operation not Permitted.'
Pretty easy to reproduce
developer@desktopimage:~/AWS$ docker run --rm -it -v ~/.aws:/home/developer/.aws -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro -u 1001:1001 alpine:latest ls -al /home/developer
total 12
drwxr-xr-x 3 root root 4096 Feb 25 14:09 .
drwxr-xr-x 1 root root 4096 Feb 25 14:09 ..
drwxr-xr-x 5 develope develope 4096 Feb 3 20:49 .aws
developer@desktopimage:~/AWS$ docker run --rm -it -v ~/.aws:/home/developer/.aws -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro -u 1001:1001 alpine:latest ls -al /home
total 12
drwxr-xr-x 1 root root 4096 Feb 25 14:09 .
drwxr-xr-x 1 root root 4096 Feb 25 14:09 ..
drwxr-xr-x 3 root root 4096 Feb 25 14:09 developer