colima: Cannot chown or chmod bind mounted files/dirs

Hello and thank you for the awesome project!

I’m running into an inconsistency between docker for mac and lima. With docker for mac, I can successfully chown & chmod bind mounted files/dirs within a container.

If I attempt this with colima I get chown: file.txt: Permission denied

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 7
  • Comments: 23 (4 by maintainers)

Most upvoted comments

This is how I solved it. I had to write mounts for ~ twice: with absolute path and with ~.

  1. Put this into your /Users/<username>/.lima/_config/override.yaml:

    mountType: 9p
    mounts:
      - location: "/Users/<username>"
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
      - location: "~"
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
      - location: /tmp/colima
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
    
  2. colima delete

  3. colima start --mount-type 9p

Versions:

  • MBP M1 MacOS Monterey (12.5)
  • lima 0.13.0
  • colima 0.4.6

Has anyone been able to solve it?

Same use case.- Resolved it following @bofm 's comment in three easy steps:

1. Stop colima and create override.yaml file

🧨 To start from scratch I deleted all colima profiles first:

➜ colima list | awk "/$(uname -m)/ {print \$1}" | while read i ; do colima stop -p ${i} ; colima delete -p ${i} ; done
➜ colima stop

➜ [ -d "${HOME}/.colima/_config" ] || mkdir -vp "${HOME}/.colima/_config"

➜ cat << EOF > ${HOME}/.colima/_config/override.yaml
mountType: 9p
mounts:
  - location: ${HOME}
    writable: true
    9p:
      securityModel: mapped-xattr
      cache: mmap
  - location: "~"
    writable: true
    9p:
      securityModel: mapped-xattr
      cache: mmap
  - location: /tmp/colima
    writable: true
    9p:
      securityModel: mapped-xattr
      cache: mmap
EOF

2. Edit the template

⚠️ Make sure you have: mountType: 9p

➜ colima template

3. Then start colima editing the configuration file before start:

⚠️ Make sure you have: mountType: 9p

➜ colima start --edit

Tried your docker-compose.yaml example:

version: '3'
services:
  database:
    image: postgres:15.4-alpine
    volumes:
      - ./data/database:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: 'directus'
      POSTGRES_PASSWORD: 'directus'
      POSTGRES_DB: 'directus'
➜  ls -lao
total 8
drwxr-xr-x   3 user   96 Nov 15 08:54 ./
drwxr-xr-x  23 user  736 Nov 15 08:53 ../
-rw-r--r--   1 user  244 Nov 15 08:49 docker-compose.yaml
➜  docker compose up -d
[+] Building 0.0s (0/0)                                    docker:colima
[+] Running 2/2
 βœ” Network colima_default       Created                    0.1s
 βœ” Container colima-database-1  Started                    0.0s
➜  ls -lao
total 8
drwxr-xr-x   4 user  128 Nov 15 08:54 ./
drwxr-xr-x  23 user  736 Nov 15 08:53 ../
drwx------@  3 user   96 Nov 15 08:54 data/
-rw-r--r--   1 user  244 Nov 15 08:49 docker-compose.yaml
➜  tree -d data
data
└── database
    β”œβ”€β”€ base
    β”‚Β Β  β”œβ”€β”€ 1
    β”‚Β Β  β”œβ”€β”€ 16384
    β”‚Β Β  β”œβ”€β”€ 4
    β”‚Β Β  └── 5
    β”œβ”€β”€ global
    β”œβ”€β”€ pg_commit_ts
    β”œβ”€β”€ pg_dynshmem
    β”œβ”€β”€ pg_logical
    β”‚Β Β  β”œβ”€β”€ mappings
    β”‚Β Β  └── snapshots
    β”œβ”€β”€ pg_multixact
    β”‚Β Β  β”œβ”€β”€ members
    β”‚Β Β  └── offsets
    β”œβ”€β”€ pg_notify
    β”œβ”€β”€ pg_replslot
    β”œβ”€β”€ pg_serial
    β”œβ”€β”€ pg_snapshots
    β”œβ”€β”€ pg_stat
    β”œβ”€β”€ pg_stat_tmp
    β”œβ”€β”€ pg_subtrans
    β”œβ”€β”€ pg_tblspc
    β”œβ”€β”€ pg_twophase
    β”œβ”€β”€ pg_wal
    β”‚Β Β  └── archive_status
    └── pg_xact

28 directories
➜  docker exec -it colima-database-1 psql -U directus -c '\l'
                                                List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider |   Access privileges
-----------+----------+----------+------------+------------+------------+-----------------+-----------------------
 directus  | directus | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 postgres  | directus | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 template0 | directus | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/directus          +
           |          |          |            |            |            |                 | directus=CTc/directus
 template1 | directus | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/directus          +
           |          |          |            |            |            |                 | directus=CTc/directus
(4 rows)

darwin21.0
colima version 0.6.1
limactl version 0.18.0
x86_64

This is how I solved it. I had to write mounts for ~ twice: with absolute path and with ~.

  1. Put this into your /Users/<username>/.lima/_config/override.yaml:
    mountType: 9p
    mounts:
      - location: "/Users/<username>"
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
      - location: "~"
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
      - location: /tmp/colima
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
    
  2. colima delete
  3. colima start --mount-type 9p

Versions:

  • MBP M1 MacOS Monterey (12.5)
  • lima 0.13.0
  • colima 0.4.6

It can’t work by path/Users/<username>/.lima/_config in my version , then i chose another path /Users/<username>/.colima/_lima/_config and it works ,for reference only

  • MBP M1 MacOS Monterey (12.4)
  • lima 0.18.0
  • colima 0.6.1

This is how I solved it. I had to write mounts for ~ twice: with absolute path and with ~.

  1. Put this into your /Users/<username>/.lima/_config/override.yaml:
    mountType: 9p
    mounts:
      - location: "/Users/<username>"
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
      - location: "~"
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
      - location: /tmp/colima
        writable: true
        9p:
          securityModel: mapped-xattr
          cache: mmap
    
  2. colima delete
  3. colima start --mount-type 9p

Versions:

  • MBP M1 MacOS Monterey (12.5)
  • lima 0.13.0
  • colima 0.4.6

It can’t work by path/Users/<username>/.lima/_config in my version , then i chose another path /Users/<username>/.colima/_lima/_config and it works ,for reference only

  • MBP M1 MacOS Monterey (12.4)
  • lima 0.18.0
  • colima 0.6.1

Also worked for me. Thanks!

Has anyone been able to solve it?

My use case:

version: '3'
services:
  database:
    image: postgis/postgis:13-master
    # Required when running on platform other than amd64, like Apple M1/M2:
    platform: linux/amd64
    volumes:
      - ./data/database:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: 'directus'
      POSTGRES_PASSWORD: 'directus'
      POSTGRES_DB: 'directus'

  directus:
    image: directus/directus:10.4.0
    ports:
      - 8055:8055
    volumes:
      - ./uploads:/directus/uploads
      # If you want to load extensions from the host
      # - ./extensions:/directus/extensions
    depends_on:
      - database
    environment:
      KEY: '255d861b-5ea1-5996-9aa3-922530ec40b1'
      SECRET: '6116487b-cda1-52c2-b5b5-c8022c45e263'

      DB_CLIENT: 'pg'
      DB_HOST: 'database'
      DB_PORT: '5432'
      DB_DATABASE: 'directus'
      DB_USER: 'directus'
      DB_PASSWORD: 'directus'

      ADMIN_EMAIL: 'admin@example.com'
      ADMIN_PASSWORD: 'd1r3ctu5'

The logs are:

~/Desktop/directus-colima with node(v18.16.1) ⌚ 11:34:27
$ docker compose up
[+] Building 0.0s (0/0)                                                                                                                                           docker:colima
[+] Running 2/0
 βœ” Container directus-colima-database-1  Created                                                                                                                           0.0s 
 βœ” Container directus-colima-directus-1  Created                                                                                                                           0.0s 
Attaching to directus-colima-database-1, directus-colima-directus-1
directus-colima-database-1  | chown: changing ownership of '/var/lib/postgresql/data': Permission denied
directus-colima-database-1 exited with code 1
directus-colima-directus-1  | [15:34:30.729] INFO: Initializing bootstrap...
directus-colima-directus-1  | [15:34:55.866] ERROR: Can't connect to the database.
directus-colima-directus-1  | [15:34:55.867] ERROR: getaddrinfo ENOTFOUND database
directus-colima-directus-1  |     err: {
directus-colima-directus-1  |       "type": "Error",
directus-colima-directus-1  |       "message": "getaddrinfo ENOTFOUND database",
directus-colima-directus-1  |       "stack":
directus-colima-directus-1  |           Error: getaddrinfo ENOTFOUND database
directus-colima-directus-1  |               at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
directus-colima-directus-1  |       "errno": -3008,
directus-colima-directus-1  |       "code": "ENOTFOUND",
directus-colima-directus-1  |       "syscall": "getaddrinfo",
directus-colima-directus-1  |       "hostname": "database"
directus-colima-directus-1  |     }
directus-colima-directus-1 exited with code 1

The error is:

chown: changing ownership of '/var/lib/postgresql/data':

Simple example:

version: '3'
services:
  database:
    image: postgres:15.4-alpine
    volumes:
      - ./data/database:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: 'directus'
      POSTGRES_PASSWORD: 'directus'
      POSTGRES_DB: 'directus'

Console:

$ docker compose up
[+] Building 0.0s (0/0)                                                                                                                                                     docker:colima
[+] Running 2/0
 βœ” Network postgresql-colima_default       Created                                                                                                                                   0.0s 
 βœ” Container postgresql-colima-database-1  Created                                                                                                                                   0.0s 
Attaching to postgresql-colima-database-1
postgresql-colima-database-1  | chown: /var/lib/postgresql/data: Permission denied
postgresql-colima-database-1 exited with code 1