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

Bind mount throws error if the directory does not exit beforehand #1652

Closed
mirzaprangon opened this issue Dec 14, 2022 · 3 comments · Fixed by #2150
Closed

Bind mount throws error if the directory does not exit beforehand #1652

mirzaprangon opened this issue Dec 14, 2022 · 3 comments · Fixed by #2150
Labels
enhancement New feature or request

Comments

@mirzaprangon
Copy link

mirzaprangon commented Dec 14, 2022

Description

Discussed in rancher-sandbox/rancher-desktop#3603

Hello
I am running nerdctl on windows, using rancher desktop version 1.6.2.
I have a simple compose file with directory mounts, nothing fancy just a mysql container.

services:
  mysql_db:
    image: mysql:8.0.30
    restart: always
    volumes:
      - ./mysql_db_data:/var/lib/mysql
      - ./mysql_db_config:/etc/mysql/conf.d
    environment:
      - MYSQL_DATABASE=keycloak
      - MYSQL_ROOT_PASSWORD=root_password
      - MYSQL_USER=db_user
      - MYSQL_PASSWORD=db_password
      - TZ=Asia/Tokyo

But nerdctl compose up fails if I run without the mount directory manually first. The output I get with --debug option is as follow

WARN[0000] Ignoring: volume: Bind: [CreateHostPath]
WARN[0000] Ignoring: volume: Bind: [CreateHostPath]
INFO[0000] Ensuring image mysql:8.0.30
DEBU[0000] filters: [labels."com.docker.compose.project"==20221213githubtokenforjenkinsjobincoverity,labels."com.docker.compose.service"==mysql_db]
INFO[0000] Creating container mysql_mysql_db_1
FATA[0000] error while creating container mysql_mysql_db_1: exit status 1

I can run the compose file if I change my container engine to Dockerd/moby and use docker compose up.
If I remove the volume binds I can run the compose file with nerdctl compose up.

nerdctl compose and nerdctl run -v S\should make empty mount directories if those do not already exist like docker compose and docker run -v in windows.

Steps to reproduce the issue

  1. run nerdctl run -v mysql_db_data:/var/lib/mysql mysql:8.0.30 without creaating the mysql_db_data directory in the host.

Or

  1. Run nerdctl compose up with follwing compose file.
    services:
      mysql_db:
        image: mysql:8.0.30
        restart: always
        volumes:
          - ./mysql_db_data:/var/lib/mysql
    

Describe the results you received and expected

Recieved
nerdctl run -v mysql_db_data:/var/lib/mysql mysql:8.0.30 fails with following error

FATA[0000] failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/mnt/c/Users/mirzap/Works Folder/mysql/mysql_db_data" to rootfs at "/var/lib/mysql": stat /mnt/c/Users/mirzap/Works Folder/mysql/mysql_db_data: no such file or directory: unknown

nerdctl compose up fails with following error.

WARN[0000] Ignoring: volume: Bind: [CreateHostPath]
WARN[0000] Ignoring: volume: Bind: [CreateHostPath]
INFO[0000] Ensuring image mysql:8.0.30
DEBU[0000] filters: [labels."com.docker.compose.project"==20221213githubtokenforjenkinsjobincoverity,labels."com.docker.compose.service"==mysql_db]
INFO[0000] Creating container mysql_mysql_db_1
FATA[0000] error while creating container mysql_mysql_db_1: exit status 1

Expected
nerdctl to create the bind mount directory if it does not already exist and container properly starts without any error.

What version of nerdctl are you using?

Client:
Version: v0.23.0
OS/Arch: linux/amd64
Git commit: 660680b
buildctl:
Version: v0.10.4
GitCommit: a2ba6869363812a210fcc3ded6926757ab780b5f

Server:
containerd:
Version: v1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: 5fd4c4d144137e991c4acebb2146ab1483a97925

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

Rancher Desktop for Windows

Host information

Client:
Namespace: default
Debug Mode: false

Server:
Server Version: v1.6.8
Storage Driver: overlayfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Log: fluentd journald json-file
Storage: native overlayfs
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.16.3-microsoft-standard-WSL2
Operating System: Rancher Desktop WSL Distribution
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 12.24GiB
Name: 11-11569698
ID: 8e7f6d3b-981b-48f3-81ac-40260dd40697

@mirzaprangon mirzaprangon added the kind/unconfirmed-bug-claim Unconfirmed bug claim label Dec 14, 2022
@AkihiroSuda AkihiroSuda changed the title Bind mount in Windows throws error if the directory does not exit beforehand Bind mount throws error if the directory does not exit beforehand Dec 14, 2022
@AkihiroSuda AkihiroSuda added enhancement New feature or request and removed kind/unconfirmed-bug-claim Unconfirmed bug claim labels Dec 14, 2022
@iainnicol
Copy link

iainnicol commented Jan 9, 2023

AFAICT bind mounts simply do not work with nerdctl compose (even if the directory exists on the host beforehand). In contrast, nerdctl run will work will bind mounts, if the directory already exists on the host beforehand.

@mirzaprangon
Copy link
Author

Maybe there are discrepencies in different distribution? I can use bind mount on windows using the nerdctl shipped with RancherDesktop.

@saurik
Copy link

saurik commented Jan 15, 2023

Something similar happens if you try to mount a file into a folder that exists but is itself about to be mounted. On macOS:

$ mkdir folder
$ touch file           
$ nerdctl.lima run -it --rm -v "${PWD}/folder:/mnt" -v "${PWD}/file:/mnt/test" ubuntu ls -la /mnt/test
FATA[0000] failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/Users/administrator/file" to rootfs at "/mnt/test": open /run/containerd/io.containerd.runtime.v2.task/default/00f3d744c2b7f9ae3cc5f130cddfdbc19d31839dfc3201a59b89e65878254bdf/rootfs/mnt/test: read-only file system: unknown 
$ docker run -it --rm -v "${PWD}/folder:/mnt" -v "${PWD}/file:/mnt/test" ubuntu ls -la /mnt/test
-rw-r--r-- 1 root root 0 Jan 15 01:01 /mnt/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants