rancher-sandbox / rancher-desktop

Container Management and Kubernetes on the Desktop
https://rancherdesktop.io
Apache License 2.0
5.84k stars 272 forks source link

Docker compose in Rancher Desktop doesn't mount files #2461

Open tfbroner opened 2 years ago

tfbroner commented 2 years ago

Actual Behavior

Docker run and docker compose in Docker Desktop mounts all volumes correctly. I switched to Rancher Desktop, and used the exact same compose file. The docker run is working correctly, and the docker compose is NOT mounting directories/files correctly.

I created the following test to prove it:

Directory structure:

C:\temp>tree /f
Folder PATH listing for volume Sys
Volume serial number is D2DF-CD16
C:.
│   docker-compose.yml
└───postgresql
        10-create_users.sh
        20-create_dbs.sh

docker-compose.yml contents:

version: "3.7"

services:

  test1:
    image: ubuntu:latest
    container_name: ubuntu-test
    hostname: ubuntu-test
    command: ["ls","-la","/db"]
    #command: ["sleep","infinity"]
    volumes:
      - c:\temp\postgresql:/db:ro

Output from the docker run command:

C:\temp>docker run -it -v c:\temp\postgresql:/db:ro --name ubuntu-test ubuntu ls -la /db
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
405f018f9d1d: Pull complete
Digest: sha256:b6b83d3c331794420340093eb706a6f152d9c1fa51b262d9bf34594887c2c7ac
Status: Downloaded newer image for ubuntu:latest
total 8
drwxrwxrwx 1 root root 4096 Jun 21 11:07 .
drwxr-xr-x 1 root root 4096 Jun 24 10:56 ..
-rwxrwxrwx 1 root root  520 Jun 21 11:07 10-create_users.sh
-rwxrwxrwx 1 root root  420 Jun 21 11:07 20-create_dbs.sh

Output from the docker compose run command:

C:\temp>docker compose run test1
total 8
drwxr-xr-x 2 root root 4096 Jun 24 10:59 .
drwxr-xr-x 1 root root 4096 Jun 24 10:59 ..

Diff from inspect on both( docker run = left, docker compose run = right ):

37c37
<                 "/mnt/c/temp/postgresql:/db:ro"
---
>                 "/c/temp/postgresql:/db:ro"
84c84
<             "BlkioWeightDevice": [],
---
>             "BlkioWeightDevice": null,
95c95
<             "Devices": [],
---
>             "Devices": null,
142c142
<                 "Source": "/mnt/c/temp/postgresql",
---
>                 "Source": "/c/temp/postgresql",
166,167c166,169
<             "Image": "ubuntu",
<             "Volumes": null,
---
>             "Image": "ubuntu:latest",
>             "Volumes": {
>                 "/db": {}
>             },

Steps to Reproduce

mkdir C:\temp

Write the following contents to the c:\temp\docker-compose.yml file docker-compose.yml contents:

version: "3.7"

services:

  test1:
    image: ubuntu:latest
    container_name: ubuntu-test
    hostname: ubuntu-test
    command: ["ls","-la","/db"]
    #command: ["sleep","infinity"]
    volumes:
      - c:\temp\postgresql:/db:ro

Run the following commands:

mkdir C:\temp\postgresql
echo Hello>C:\temp\postgresql\10-create_users.sh
echo World>C:\temp\postgresql\20-create_dbs.sh
cd C:\temp
docker run -it -v c:\temp\postgresql:/db:ro --name ubuntu-test ubuntu ls -la /db
docker compose run test1

Result

Output from the docker run

total 8
drwxrwxrwx 1 root root 4096 Jun 21 11:07 .
drwxr-xr-x 1 root root 4096 Jun 24 10:56 ..
-rwxrwxrwx 1 root root  520 Jun 21 11:07 10-create_users.sh
-rwxrwxrwx 1 root root  420 Jun 21 11:07 20-create_dbs.sh

Output from the docker compose run

total 8
drwxrwxrwx 1 root root 4096 Jun 21 11:07 .
drwxr-xr-x 1 root root 4096 Jun 24 10:56 ..

Expected Behavior

Both commands should return the same output, and the volumes should be mounted in the exact same way.

Additional Information

I did full cleanup/uninstall of previously used Docker Desktop, Rancher Desktop, WSL and unregistered Debian, Ubuntu, docker-desktop, docker-desktop-data, rancher-desktop, rancher-desktop-data. I removed any profile configurations for docker and rancher desktop. I re-installed WSL, and set version 2 as default. I installed Rancher Desktop with Kubernetes disabled, but enabled it for testing which made no difference, then disabled again. I tried changing the mount point via wsl.conf to / but Rancher is hardcoded to use /mnt, so that didn't go well.

I now uninstalled Rancher Desktop, removed wsl distros, and re-installed Docker desktop, and it works as expected.

Rancher Desktop Version

1.4.1

Rancher Desktop K8s Version

1.23.6(stable) - not enabled

Which container runtime are you using?

moby (docker cli)

What operating system are you using?

Windows

Operating System / Build Version

Windows 10 Enterprise Version 10.0.19044 Build 19044

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

No response

Windows User Only

Kaspersky Endpoint Security - enabled and disabled but made no difference.

andykitch commented 2 years ago

I'm also seeing this - any update?

newphew92 commented 1 year ago

Encountering this issue, I don't see anyone talking about workarounds, can we have an update please, it's kinda a major turnoff to not be able to use docker-compose properly

jfavrod commented 1 year ago

I was having the same problem on a Mac (using Rancher 1.6). This helped me:

https://rancher.com/docs/rancher/v1.6/en/cattle/volumes/

I had to modify my docker-compose volume situation, but I did get things working.

dgilsonAfelio commented 1 year ago

Had the same. It seems to work after update to 1.7.0 and give admin access on Rancher Desktop startup.

tfbroner commented 1 year ago

Had the same. It seems to work after update to 1.7.0 and give admin access on Rancher Desktop startup.

This is interesting, I'll test this and see if it solves the problem.

tfbroner commented 1 year ago

I checked with 1.7.0 and the issue persists for me.

lgall3t commented 1 year ago

Same problem with Rancher Desktop 1.7.0 on Mageia Linux 8. I use Rancher Desktop AppImage, with moby container. Host file is mounted like a directory (bad). Host directory is mounted like a directory (good) but files in host directory are all mounted like directories (bad).

jandubois commented 1 year ago

I cannot reproduce this with Rancher Desktop 1.8 on Windows 10:

C:\temp>type docker-compose.yml
version: "3.7"

services:

  test1:
    image: ubuntu:latest
    container_name: ubuntu-test
    hostname: ubuntu-test
    command: ["ls","-la","/db"]
    #command: ["sleep","infinity"]
    volumes:
      - c:\temp\postgresql:/db:ro

C:\temp>mkdir postgresql

C:\temp>echo Hello > postgresql\10-create-users.sh

C:\temp>echo World > postgresql\20-create-dbs.sh

C:\temp>docker run -it -v c:\temp\postgresql:/db:ro --name ubuntu-test ubuntu ls -la /db
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
2ab09b027e7f: Pull complete
Digest: sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21
Status: Downloaded newer image for ubuntu:latest
total 4
drwxrwxrwx 1 root root  512 Mar 21 21:04 .
drwxr-xr-x 1 root root 4096 Mar 21 21:05 ..
-rwxrwxrwx 1 root root    8 Mar 21 21:04 10-create-users.sh
-rwxrwxrwx 1 root root    8 Mar 21 21:04 20-create-dbs.sh

C:\temp>docker compose run test1
[+] Running 1/1
 - Network temp_default  Created                                                                                   0.1s
total 4
drwxrwxrwx 1 root root  512 Mar 21 21:04 .
drwxr-xr-x 1 root root 4096 Mar 21 21:05 ..
-rwxrwxrwx 1 root root    8 Mar 21 21:04 10-create-users.sh
-rwxrwxrwx 1 root root    8 Mar 21 21:04 20-create-dbs.sh
jandubois commented 1 year ago

I also cannot reproduce this with Rancher Desktop 1.8.0 on macOS 12.6.3 (Intel):

$ cat docker-compose.yml
version: "3.7"

services:

  test1:
    image: ubuntu:latest
    container_name: ubuntu-test
    hostname: ubuntu-test
    command: ["ls","-la","/db"]
    #command: ["sleep","infinity"]
    volumes:
    - /tmp/rd-2461/postgresql:/db:ro

$ docker run -it -v $PWD/postgresql:/db:ro --name ubuntu-test ubuntu ls -la /db
total 16
drwxr-xr-x 1  501 dialout  128 Mar 21 20:14 .
drwxr-xr-x 1 root root    4096 Mar 21 21:09 ..
-rw-r--r-- 1  501 dialout    6 Mar 21 20:14 10-create_users.sh
-rw-r--r-- 1  501 dialout    6 Mar 21 20:14 20-create_dbs.sh

$ docker compose run test1
total 16
drwxr-xr-x 1  501 dialout  128 Mar 21 20:14 .
drwxr-xr-x 1 root root    4096 Mar 21 21:09 ..
-rw-r--r-- 1  501 dialout    6 Mar 21 20:14 10-create_users.sh
-rw-r--r-- 1  501 dialout    6 Mar 21 20:14 20-create_dbs.sh
jandubois commented 1 year ago

FWIW, I ran the test on macOS without allowing administrative access.

There isn't anything I can do about this unless somebody can provide additional details to reproduce it, so I'm closing it for now.

mwm-twx commented 5 months ago

@jandubois I am experiencing this issue on newly installed Rancher Desktop 1.13.1, running on Windows 11. I see the same results as the original reporter when running the setup described in this issue.

Additionally, I found that mounts supplied directly to the docker compose run command are correctly using /mnt/c/, even when there are additional mounts in docker-compose.yml:

# Change volumes to mount only one of the scripts
volumes:
  - c:\temp\postgresql\10-create_dbs.sh:/db/10-create_dbs.sh:ro
> docker compose run -v C:\temp\postgresql\10-create_users.sh:/db/create_users.sh:ro test1
total 12
drwxr-xr-x 3 root root 4096 Apr 11 16:54 .
drwxr-xr-x 1 root root 4096 Apr 11 16:54 ..
drwxr-xr-x 2 root root 4096 Apr 11 16:54 10-create_dbs.sh
-rwxrwxrwx 1 root root    7 Apr 11 16:50 create_users.sh
jandubois commented 5 months ago

I'm re-opening the issue to see if I can reproduce it with 1.13.1 on Windows 11.

mwm-twx commented 5 months ago

@jandubois I found what appears to be the issue and explains the difficulties reproducing the original problem. The issue appears related to the COMPOSE_CONVERT_WINDOWS_PATHS environment variable. If the conversion is enabled, compose YAML volumes aren't mounted correctly; this is true whether the path is an explicit windows path or a relative one like ./postgresql. Turning this option off causes the volumes to work, even with explicit windows paths.

I'm not sure why this option breaks volumes, nor why windows paths work without it, but I guess I can remove it for now.

domq commented 2 months ago

Today I encountered this issue, I think, on Mac OS X Sonoma 14.5 (23F79), Rancher Desktop 1.13.1. However, stopping and restarting Rancher Desktop made the problem go away.