dockerdocker-composechown

chown inside container failed: No such file or directory


docker-compose.yml contains the following

services:
  unbound-db-socket:
    image: busybox:latest
    container_name: unbound-db-socket
    init: true
    tty: true
    command: [/bin/sh -c "chown -R 1000:1000 /usr/local/unbound/cachedb.d/"]
    volumes:
       - "cachedb.d:/usr/local/unbound/cachedb.d/"

volumes:
  cachedb.d:

networks:
  bridge:

When running docker compose up, I'm getting the error

"unbound-db-socket  | [FATAL tini (7)] exec /bin/sh -c "chown -R 1000:1000 /usr/local/unbound/cachedb.d/" failed: No such file or directory"

What am I doing wrong?

Added [] to the command Added "" to the volume path


Solution

  • BusyBox uses sh -c differently, and tini is trying to execute the whole command as a binary rather than passing it to the shell.

    Modify command like this:

    command: ["/bin/sh", "-c", "mkdir -p /usr/local/unbound/cachedb.d && chown -R 1000:1000 /usr/local/unbound/cachedb.d/"]
    
    services:
      unbound-db-socket:
        image: busybox:latest
        container_name: unbound-db-socket
        init: true
        tty: true
        command: ["/bin/sh", "-c", "mkdir -p /usr/local/unbound/cachedb.d && chown -R 1000:1000 /usr/local/unbound/cachedb.d/"]
        volumes:
           - "cachedb.d:/usr/local/unbound/cachedb.d/"
    
    volumes:
      cachedb.d:
    
    networks:
      bridge: