Docker Community Forums

Share and learn in the Docker community.

Unable to find the file while docker run

Dockerfile:
FROM centos

RUN mkdir /test
COPY ./sample.sh /test

CMD [“sh”, “/test/sample.sh”]

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

Here 2 problems:
The output says
sh: /test/sample.sh: No such file or directory

Also, 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.

You’re copying your local /app/ folder to the /app/ folder in the running Docker container (as mentioned in the comments) creating /app/app/server.py in the Docker container.

How to resolve
A simple fix will be to change

COPY . /app
to

COPY ./app/server.py /app/server.py
Explanation
The command COPY works as follows:

COPY <LOCAL_FROM> <DOCKER_TO>
You’re selecting everything in the folder where the Dockerfile resides, by using . in your first COPY, thereby selecting the local /app folder to be added to the Docker’s folder. The destination you’re allocating for it in the Docker container is also /app and thus the path in the running container becomes /app/app/… explaining why you can’t find the file.