nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

How to automatically create mounted directory?

Open icefery opened this issue 4 years ago • 4 comments

I use compose like this:

services:
  mysql:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=root
    ports:
      - 3306:3306
    volumes:
      - ../../data/mysql/var/lib/mysql/:/var/lib/mysql/

Which works with docker-compose:1.29.* (pip install docker-compose), the mounted directory will be created automatically as follow:

/d/docker
|--linux
   |--mysql
      |--docker-compose.yml
|--data # automatically created
   |--var
      |--lib
         |--mysql 

However, nerdctl compose up -d got:

FATA[0000] failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/d/docker/data/mysql/var/lib/mysql" to rootfs at "/var/lib/mysql/" caused: stat /d/docker/data/mysql/var/lib/mysql: no such file or directory: unknown

Am I using it as wrong way?

icefery avatar Oct 28 '21 03:10 icefery

If you dont need to bind the exact directory, you can change the type from from Bind (compose detects the path there) and put into Volume mode. Something like:

    volumes:
      - mysql_data:/var/lib/mysql/

or

    volumes:
      - type: Volume
        target: /var/lib/mysql/
        source: mysql_data

I'm studying the code for a possible adjust. But I'm new here. :-)

jopapo avatar Jan 08 '22 23:01 jopapo

@jopapo @AkihiroSuda

Is there something new you can share with us?

I get the same error mentioned by @icefery and can't figure it out how to get it to run. I couldn't get it to run with the Volume mode either.

myimage:
  network_mode: bridge
  build: ./myimage
  dns:
    - 8.8.8.8
  ports:
    - 443:443
  volumes:
    - /tmp/myvolume:/tmp/myvolume:z
FATA[0000] failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/tmp/myvolume" to rootfs at "/tmp/myvolume" caused: stat /tmp/myvolume: no such file or directory: unknown

Interesting(?) sidefact: I tried the same setup with Docker/Docker Desktop and got the same error but as soon as I disabled "Use gRPC FUSE for file sharing" and started using the legacy osfx file sharing it worked.

byt3pool avatar Feb 01 '22 14:02 byt3pool

I've ran into this issue too. To me (and I'll admit I'm not an expert at all), it seems nerdctlis trying to access the file system as root and not as the current user. Thus, for instance, my binding to ~/data/mongodb goes to /home/root/data/mongodb and that directory doesn't exist and can't be created, because root is "disabled".

Using the volume mode worked though. So, thanks @jopapo for the tip.

Scott

smolinari avatar Mar 03 '22 12:03 smolinari

I've ran into this issue too.

luya0000 avatar Mar 15 '22 00:03 luya0000