最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

docker - chown inside container failed: No such file or directory - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question asked Mar 10 at 19:41 BrunnBrunn 31 bronze badge 2
  • Hello! I believe you shouldn't enclose your command by [] – Eternal Dreamer Commented Mar 10 at 20:03
  • Or if you do, you need commas between the words in the YAML array; [/bin/sh, -c, "chown -R ..."]. This usage doesn't need the sh -c wrapper and I'd remove it. Also remember that the command: is the only thing the container will do, so this container will exit immediately once it's run the chown command. – David Maze Commented Mar 10 at 20:09
Add a comment  | 

1 Answer 1

Reset to default 0

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/"]
  • This ensures the directory exists before attempting to change ownership.

  • Output

  • docker-compose.yml file after update

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:
发布评论

评论列表(0)

  1. 暂无评论