Paul Serikov
Paul Serikov

Reputation: 3111

Corrent passing arguments to docker entrypoint

I have a super dumb script

$ cat script.sh 
cat <<EOT > entrypoint.sh 
#!/bin/bash
echo "$@"
EOT

docker run -it --rm -v $(pwd)/entrypoint.sh:/root/entrypoint.sh --entrypoint /root/entrypoint.sh bash:4 Hello World

But when I run script I got strange error:

$ sh script.sh 
standard_init_linux.go:207: exec user process caused "no such file or directory"

Why script does not print Hello world ?

Upvotes: 0

Views: 1076

Answers (2)

BMitch
BMitch

Reputation: 263726

standard_init_linux.go:207: exec user process caused "no such file or directory"

The above error means one of:

  • Your script actually doesn't exist. This isn't likely with your volume mount but it doesn't hurt to run the container without the entrypoint, just open a shell with the same volume mount and list the file to be sure it's there. It's possible for the volume mount to fail on desktop versions of docker where the directory isn't shared to the docker VM and you end up with empty folders being created inside the container instead of mounting your file. When checking from inside of another container, also make sure you have execute permissions on the script.

  • If it's a script, the first line pointing to the interpreter is invalid. Make sure that command exists inside the container. E.g. alpine containers typically do not ship with bash and you need to use /bin/sh instead. This is the most common issue that I see.

  • If it's a script, similar to above, make sure your first line has linux linefeeds. A windows linefeed adds and extra \r to the name of the command trying to be run, which won't be found on the linux side.

  • If the command is a binary, it can refer to a missing library. I often see this with "statically" compiled go binaries that didn't have CGO disabled and have links to libc appear when importing networking libraries.

  • If you use json formatting to run your command, I often see this error with invalid json syntax. This doesn't apply to your use case, but may be helpful to others googling this issue.

This list is pulled from a talk I gave at last year's DockerCon: https://sudo-bmitch.github.io/presentations/dc2018/faq-stackoverflow.html#59

Upvotes: 2

Dmitrii
Dmitrii

Reputation: 917

First of all:

Request

 docker run -it --rm bash:4 which bash

Output

/usr/local/bin/bash

So

 #!/bin/bash

Should be changed to

#!/usr/local/bin/bash

And

docker run -it --rm -v $(pwd)/entrypoint.sh:/root/entrypoint.sh --entrypoint /root/entrypoint.sh bash:4 Hello World

Gives you

Hello World

Update

Code

cat <<EOT > entrypoint.sh 
#!/bin/bash
echo "$@"
EOT

Should be fixed as

#!/usr/bin/env bash

cat <<EOT > entrypoint.sh
#!/usr/bin/env bash

echo "\$@"
EOT

Upvotes: 1

Related Questions