skip to Main Content

Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime-deps:7.0.10-alpine3.18-amd64
ARG APP_DIR=/var/lib/app/
WORKDIR $APP_DIR
# etc.
ENTRYPOINT ["MyApp"]     # executable file located at /var/lib/app/MyApp

When running that container:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "MyApp": executable file not found in $PATH: unknown.

I specified WORKDIR, so why is the executable not found?

(It works if I use ENTRYPOINT ["/var/lib/app/MyApp"], so it’s not a permissions issue.)

3

Answers


  1. Chosen as BEST ANSWER

    There are some shortcomings in the docs for the interaction between WORKDIR and ENTRYPOINT.

    After much trial and error, this is the only way that works for me:

    FROM alpine:3.18
    ARG APP_DIR=/var/lib/app/
    ENV APP_DIR=${APP_DIR}                          # <---
    WORKDIR $APP_DIR
    # etc.
    ENTRYPOINT ["sh", "-c", "${APP_DIR}MyApp"]      # <---
    

  2. To successfully run your example, you can either use:

    ENTRYPOINT ["sh", "script.sh"]
    

    or

    ENTRYPOINT ./script.sh
    

    The reason is

    Unlike the shell form, the exec form does not invoke a command shell.

    and therefore you are missing $PWD. (link to the docs)

    See the difference:

    • ENTRYPOINT ["env"] (Exec form)
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    HOSTNAME=a5f4e8cf8287
    TERM=xterm
    HOME=/root
    
    • ENTRYPOINT ["sh", "-c", "env"] (Exec form)
    HOSTNAME=0ce315379bef
    SHLVL=1
    HOME=/root
    TERM=xterm
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    PWD=/var/lib/app
    
    • ENTRYPOINT env (Shell form)
    HOSTNAME=d4f8422cf9e0
    SHLVL=1
    HOME=/root
    TERM=xterm
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    PWD=/var/lib/app
    
    Login or Signup to reply.
  3. If the PATH does not contain the current directory, then you need to explicitly request a binary in the current directory with a ./:

    ENTRYPOINT ["./MyApp"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search