In a docker-compose.yml file, I have an entrypoint which should copy files to a bind mount so that I can retrieve them from the host:

version: '3.9'

  entrypoint: cp /foo/*.txt /data
    - ./data:/data

But each time I run this container, the log says: cp: cannot stat '/foo/*.txt': No such file or directory. On the other hand, if I enter a full file name, it works very well.

I also tried: entrypoint: ['cp', '/foo/*.txt', '/data'] but the same error occurs.

Ref: https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact

How could I use a wildcard for copying files in my compose service?


docker --version
Docker version 20.10.21, build baeda1f

cat /etc/lsb-release | grep DESCRIPTION
  • I'm not sure if this works (and I cannot test it now): entrypoint: sh -c 'cp /foo/*.txt /data' Commented Nov 5, 2022 at 22:14
  • It seems to work, but what I don't really understand is that running entrypoint: cp /foo/*.txt /data should already be called with /bin/sh -c in front in such so-called "shell form" according to: docs.docker.com/engine/reference/builder/…
    – s.k
    Commented Nov 5, 2022 at 22:25
  • 1
    I'm thinking that docker-compose is parsing the cp /foo/*.txt /data as cp /foo/\*.txt /data. And therefore the * is taken as character and not as wildcard. Commented Nov 5, 2022 at 22:49
  • How do you run the container? Are you using docker run? If so, try debugging with strace docker run, maybe you could see the reason why the container is failing. (the wildcard is taken as character perhaps) Commented Nov 5, 2022 at 22:51

1 Answer 1


Characters like * are interpreted by the shell, so you need to invoke a shell to handle it (e.g., sh -c 'cp /foo/*.txt /data'). Otherwise, those parameters are being passed to exec, which does not know how to handle *, and the error you've described happens.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .