5

I'm trying to run an existing binary file in a Docker container.

Files in current folder:

$ ls .
app  Dockerfile  run.sh

Dockerfile:

FROM alpine:latest
COPY . /app/
RUN chmod +x /app/run.sh && chmod +x /app/app
WORKDIR /app
ENTRYPOINT ["./run.sh"]

run.sh:

#!/bin/sh
./app
ls

(The ls command is used to check if the app not exists)

Build command and outputs:

$ sudo docker build . -t app_test
Sending build context to Docker daemon  3.427MB
Step 1/5 : FROM alpine:latest
 ---> 11cd0b38bc3c
Step 2/5 : COPY . /app/
 ---> 4c69dfe88b2e
Step 3/5 : RUN chmod +x /app/run.sh && chmod +x /app/app
 ---> Running in 0dbdc9045827
Removing intermediate container 0dbdc9045827
 ---> 9193aeee2c8f
Step 4/5 : WORKDIR /app
 ---> Running in 9ecb2ad7c3f1
Removing intermediate container 9ecb2ad7c3f1
 ---> 1c748d0cb0b2
Step 5/5 : ENTRYPOINT ["./run.sh"]
 ---> Running in 24ebb7500202
Removing intermediate container 24ebb7500202
 ---> adcd6e94a37f
Successfully built adcd6e94a37f
Successfully tagged app_test:latest

Run command:

$ sudo docker run -it app_test
./run.sh: line 2: ./app: not found
Dockerfile  app         run.sh

From the output of ls command, we can find app exists, but it seems sh cannot find it.

I also tried run ./app directly or use ["sh", "run.sh"] instead in ENTRYPOINT or CMD, but it doesn't help.

EDIT: This app is a closed source software and only a compiled executable is distributed. I'm sorry I cannot provide more information.

CatMe0w
  • 63
  • 1
  • 5
  • Does it work if you change to, say, `FROM ubuntu:18.04`? (There are technical reasons it might.) – David Maze Aug 09 '18 at 12:56
  • You can try to add `.` to your `PATH` environment variable. – Dominique Aug 09 '18 at 12:59
  • Are you sure you can run app from alpine? They use a custom libc, which can pose problems. Did you try `./app` as entry point? You should use @mlameiras's solution to troubleshoot this point (actually running app). – Aif Aug 09 '18 at 13:48
  • Since Stack Overflow hides the Close reason from you: *Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve).* – jww Aug 09 '18 at 22:13
  • That should be working What are the contents of the app? Is it by any chance a bash script starting with `#!/bin/bash` ? Can you try using `sh app` instead of `./app` in run.sh? You can also debug your container with `docker run -it --entrypoint=/bin/sh app_test` and try running your app manually do debug the problem – mlameiras Aug 09 '18 at 13:28

1 Answers1

9

If app is a shell script, then the error refers to the first line of that script, e.g. #!/bin/bash if /bin/bash doesn't exist locally. Can also be windows linefeeds breaking that line.

If app is an executable, then the error is from linked libraries. Use ldd app to see what that binary is linked against. With alpine, the issue is often glibc.

BMitch
  • 231,797
  • 42
  • 475
  • 450