multipass icon indicating copy to clipboard operation
multipass copied to clipboard

Docker alias requires start path alignment to be 100% portable

Open Fmstrat opened this issue 3 years ago • 5 comments

Describe the bug Commands using docker or docker-compose are not 100% portable to multipass without path handling.

To Reproduce How, and what happened?

  1. multipass launch --disk 100G --mem 16G --cpus 8 docker
  2. multipass exec docker -- sudo apt install docker-compose
  3. multipass mount --uid-map $(id -u):1000 --gid-map $(id -g):1000 ${HOME} docker
  4. multipass alias docker:docker
  5. multipass alias docker:docker-compose
  6. cd ~/Documents
  7. echo "TEST=1" > env
  8. docker run -ti --rm --env-file ./env alpine sh

Expected behavior A successful shell in alpine with the env set. Instead:

docker: open ./env: no such file or directory.
See 'docker run --help'.

This is because it's running in /home/ubuntu instead of /Users/<myuser>/Documents. This is especially problematic with docker-compose, since the most common use is a docker-compose.yml file in the path.

It would be nice if the alias command had an option to specify an on-demand current path. Such as:

multipass alias -c docker:docker

So without -c, you would get:

$ multipass alias docker:pwd testing
$ testing
/home/ubuntu

Or with it:

$ multipass alias -c docker:pwd testing
$ testing
/Users/<myuser>

Additional info

  • OS: macOS 12.1
  • 1.8.1+mac
  • Name: docker State: Running IPv4: 192.168.64.5 172.17.0.1 Release: Ubuntu 21.10 Image hash: 30fbec2ddf69 (Ubuntu 21.10) Load: 0.00 0.00 0.00 Disk usage: 1.9G out of 96.7G Memory usage: 256.7M out of 15.6G Mounts: /Users/<myuser> => /Users/<myuser> UID map: 501:1000 GID map: 20:1000

Additional context Labeling as bug instead of feature since it impedes workflow with existing development methodologies.

Fmstrat avatar Jan 31 '22 16:01 Fmstrat

Hi @Fmstrat, thanks for reporting.

Indeed we're thinking on how to improve on this, most likely automatically mapping mounted paths when using an alias. A default working directory would also be an option along what you describe.

Saviq avatar Jan 31 '22 17:01 Saviq

Hi @Fmstrat, thanks for reporting.

Indeed we're thinking on how to improve on this, most likely automatically mapping mounted paths when using an alias. A default working directory would also be an option along what you describe.

Great to hear. A default working directory could prove difficult for many work cases, however. What if you contribute to multiple projects, and require commands to be run from each of those paths? You would have to unmount/mount or realias every time. I know I'm an N of 1, but pass-through of the current path (with failure if path does not exist in multipass vm) seems to alleviate any portability issues.

Fmstrat avatar Jan 31 '22 17:01 Fmstrat

@Fmstrat oh by "default" I meant per-alias default, so exactly what you described.

We'll report back here on what we plan to implement and gather feedback.

Saviq avatar Jan 31 '22 17:01 Saviq

@Saviq great, thanks! And.. maybe I'm just reading it odd, but "per-alias" default sounds something like:

multipass alias -d /path docker:docker

Which would still cause problems for "running from the current path" as soon as you change directories. Thanks again.

Fmstrat avatar Jan 31 '22 18:01 Fmstrat

@Fmstrat it's no worse than the current default of $HOME :)

For "running from the current path", that's what I described as auto-mapping mounted paths. So if your current directory on the host is mounted in the target instance, that would get automatically translated to the respective path in the instance. They may not be the same (and certainly won't be if your host is Windows).

Saviq avatar Feb 01 '22 16:02 Saviq

I believe this is actually fixed by https://github.com/canonical/multipass/pull/2535. I'm closing this, but please reopen if this is not the case.

townsend2010 avatar Aug 30 '22 16:08 townsend2010