Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker command's -v option to mount a file causes it to be mounted as a directory if the local path is not specified #6867

Open
cspencer404 opened this issue May 10, 2024 · 0 comments
Labels
kind/bug Something isn't working triage/need-to-repro Needs to be reproduced by dev team triage/next-candidate Discuss if it should be moved to "Next" milestone

Comments

@cspencer404
Copy link

cspencer404 commented May 10, 2024

Actual Behavior

For the docker command, using the -v option to mount a file causes it to be mounted as a directory when the local path is not specified

Steps to Reproduce

Create a test file

$ cat "Hello World" > test.txt

Mount it in docker using "-v" option for volume mount, get interactive shell in the container

$ docker run -it -v test.txt:/test.txt alpine:latest /bin/sh

Result

List files shows "test.txt" was mounted as a directory, not a file

$ ls -l /
...
drwxr-xr-x    2 root     root          4096 May  9 20:49 test.txt    <--- is a DIR, should be a FILE

Expected Behavior

The file should be mounted as a regular file

-rwxr-xr-x    1 501      dialout        132 May  9 20:49 test.txt

Additional Information

Work-around

When using the local path to the file, the -v option works correctly:

$ docker run -it -v ./test.txt:/test.txt alpine:latest "/bin/sh"

Or, using --mount option instead of -v works correctly, because it requires the path

$ docker run -it --mount type=bind,source=./test.txt,target=/test.txt alpine:latest /bin/sh

$ ls -l then shows:

-rwxr-xr-x    1 501      dialout        132 May  9 20:49 test.txt

Using --mount without the local path gives an error:

docker: Error response from daemon: invalid mount config for type "bind": invalid mount path: 'test.txt' mount path must be absolute.

Rancher Desktop Version

1.13.1

Rancher Desktop K8s Version

n/a

Which container engine are you using?

moby (docker cli)

What operating system are you using?

macOS

Operating System / Build Version

MacOS Ventura 13.6.6 (22G630)

What CPU architecture are you using?

x64

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

None

Windows User Only

No response

@cspencer404 cspencer404 added the kind/bug Something isn't working label May 10, 2024
@cspencer404 cspencer404 changed the title Docker command's -v option to mount a file causes it to be mounted as a directory Docker command's -v option to mount a file causes it to be mounted as a directory if the local path is not specified May 10, 2024
@cspencer404 cspencer404 reopened this May 10, 2024
@mook-as mook-as added triage/next-candidate Discuss if it should be moved to "Next" milestone triage/need-to-repro Needs to be reproduced by dev team labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/need-to-repro Needs to be reproduced by dev team triage/next-candidate Discuss if it should be moved to "Next" milestone
Projects
None yet
Development

No branches or pull requests

2 participants