I'm doing something extremely simple. Here is my Dockerfile
:
FROM alpine:latest
ADD hello.sh /bin/hello
RUN chmod +x /bin/hello
CMD /bin/hello
Then I build the image:
docker build -t hello .
Then I run the image:
docker run hello
And here is the output:
/bin/sh: /bin/hello: not found
Why is this happening? If I run:
docker run hello cat /bin/hello
I can see the content of my script, which makes me even more confused.
If you use the default storage driver overlay2, then your Docker images are stored in /var/lib/docker/overlay2 . There, you can find different files that represent read-only layers of a Docker image and a layer on top of it that contains your changes.
To summarize, follow these steps to copy a file from a Docker container to a host machine: Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container.
The Docker CLI provides the –mount and –volume options with a run command to bind a single file or directory. Both flags work similarly but have different syntaxes. As a result, we can use them interchangeably.
In my case the problem was that the line-endings for the script were Windows
encoded instead of Linux
. (Note: This was actually caused by git
automatically converting them, which I disabled)
The first line of the script provides the file path to the shell. Because of the extra \r
that is included with Windows EOL the system was trying attaching that hidden character to the filename and that's what caused the Not Found
error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With