Docker Community Forums

Share and learn in the Docker community.

Bash file isn't executing

docker

(Amankh99) #1

I want my bash file to run whenever I the run the docker image, so firstly I created the Dockerfile inside a new directory say ‘demo’ and in that directory demo I created a new directory ‘home’ and in that directory I’ve my bash file - ‘testfile.sh’.
Here is my docker file -
FROM ubuntu
MAINTAINER Aman Khandelwal
COPY . /home
CMD /home/testfile.sh

On building it with command - 'sudo docker build -t amankh99/hello .'
the following output was received -
Sending build context to Docker daemon 3.584kB
Step 1/4 : FROM ubuntu
—> 0458a4468cbc
Step 2/4 : MAINTAINER Aman Khandelwal
—> Using cache
—> 98fbe31ed233
Step 3/4 : COPY . /home
—> Using cache
—> 7e52ff3439e2
Step 4/4 : CMD /home/testfile.sh
—> Using cache
—> 1d2660df6387
Successfully built 1d2660df6387
Successfully tagged amankh99/hello:latest

But when I run it with command - 'sudo docker run --name test -it amankh99/hello’
it says - 'bin/sh: 1: /home/testfile.sh: not found’
After having build successfully why it is unable to found the file.
I want to convert this container in image and want to push on docker hub, so that I can run this with simple run command as we run the hello-world(sudo docker run hello-world) , I get my bash file executed, so what changes in dockerfile can I do to acheive this.


(Amankh99) #2

I’ve found the mistake, thanks for the attention.