Home > Software engineering >  How to run a bash script from a Dockerfile on a Mac
How to run a bash script from a Dockerfile on a Mac

Time:12-11

I'm trying to run a bash script from a Docker Image on a Mac. Here is my Dockerfile

FROM bash
ADD app.sh /
ENTRYPOINT ["/bin/bash", "/app.sh"]

Error

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown.

This is a simple exercise in creating Docker Images where I need to execute app.sh when I run docker run.

Any idea what I'm doing wrong?

CodePudding user response:

According to your error message, the file /bin/bash does not exist in your Docker image. Why is this?

The bash image puts the bash executable at /usr/local/bin/bash. Here's how I determined this:

$ docker run -it bash
bash-5.1# which bash
/usr/local/bin/bash
bash-5.1# 

I ran the bash image with -it to make it interactive, then used the which command to give me the full path to bash, which is /usr/local/bin/bash.

For that reason, you need to change your Dockerfile like this:

FROM bash
ADD app.sh /
ENTRYPOINT ["/usr/local/bin/bash", "/app.sh"]
  • Related