-1

I have the following Dockerfile:

FROM ubuntu:19.10
WORKDIR /gen
COPY script.sh ./

RUN chmod +x script.sh && export PATH="/gen/:$PATH"

ENTRYPOINT [ "script.sh" ]

It builds fine, but I cannot execute it. The solution from post is to add the full path to the script (ENTRYPOINT [ "/gen/script.sh" ]), which does not work.

Adding the folder to PATH also does not work. Why is that?

Error: docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"script.sh\": executable file not found in $PATH": unknown.

EDIT: The problem comes from me calling the container with docker run --rm -v some/dir:/gen containerName.

franklinsijo
  • 17,784
  • 4
  • 45
  • 63
User12547645
  • 6,955
  • 3
  • 38
  • 69

1 Answers1

2

The problem is that you did not modify your PATH variable. Using export in a RUN statement will not be persistent. You need to set environment variables with ENV.

FROM ubuntu:19.10
WORKDIR /gen
COPY script.sh ./

RUN chmod +x script.sh
ENV PATH="/gen:$PATH"

ENTRYPOINT ["script.sh"]

If you run the Docker image while mounting a volume to /gen, you will overwrite the /gen directory and your script will not be found.

jkr
  • 17,119
  • 2
  • 42
  • 68