skip to Main Content

Dockerfile

FROM centos

RUN mkdir /test

#its ensured that sample.sh exists where the dockerFile exists & being run
 
COPY ./sample.sh /test

CMD ["sh", "/test/sample.sh"]

Docker run cmd:

docker run -d -p 8081:8080 --name Test -v /home/Docker/Container_File_System:/test test:v1

Log output :

sh: /test/sample.sh: No such file or directory

There are 2 problems here.

  • The output says sh: /test/sample.sh: No such file or directory
  • as I have mapped a host folder to container folder, I was expecting the test folder & the sample.sh to be available at /home/Docker/Container_File_System post run, which did not happen

Any help is appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    The problem is in volume mapping. If I create a volume and map it subsequently it works fine, but directly mapping host folder to container folder does not work.

    Below worked fine

    docker volume create my-vol
    
    docker run -d -p 8081:8080 --name Test -v my-vol:/test test:v1
    

  2. When you map a folder from the host to the container, the host files become available in the container. This means that if your host has file a.txt and the container has b.txt, when you run the container the file a.txt becomes available in the container and the file b.txt is no longer visible or accessible.

    Additionally file b.txt is not available in the host at anytime.

    In your case, since your host does not have sample.sh, the moment you mount the directory, sample.sh is no longer available in the container (which causes the error).
    What you want to do is copy the sample.sh file to the correct directory in the host and then start the container.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search