Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running shell script while building docker image

I have a custom package with install.sh script, which I want to run while building a docker image (meaning - put ./install.sh inside Dockerfile). I could have ran it along with the container, but I want to have an image that contains the required packages (which are mentioned in the install script).

What I tried:

  1. RUN /bin/sh/ -c "./install.sh"
  2. RUN ./install.sh

It errors out saying -

/bin/sh install.sh not found

or

/bin/sh ./install.sh not found

This might be a repeated question, but I haven't found an answer to this anywhere. Any help would be appreciated.

like image 247
anjali Avatar asked Jan 28 '23 04:01

anjali


1 Answers

You must copy your install.sh into docker image with this command in your dockerfile:

COPY install.sh /tmp

Then use your RUN command to run it:

RUN /bin/sh -c "/tmp/install.sh"

or

RUN sh /tmp/install.sh

Don't forget to make install.sh executable before run it:

chmod +x /tmp/install.sh

like image 56
MSaadat Avatar answered Jan 31 '23 08:01

MSaadat