Snowcrash
Snowcrash

Reputation: 86367

Dockerfile build: FileNotFoundError: [Errno 2] No such file or directory

Why am I getting FileNotFoundError: [Errno 2] No such file or directory when, during my Dockerfile build, the file is clearly put on the filesystem. E.g. here's the latest output from Docker:

Step 8/9 : COPY https.py /tmp
 ---> Using cache
 ---> 685946ede218
Step 9/9 : RUN /usr/bin/python3 /tmp/https.py
 ---> Running in c1c2acba9483
Traceback (most recent call last):
  File "/tmp/https.py", line 16, in <module>
    certfile='/etc/nginx/certs/cert.pem', server_side=True)
  File "/usr/lib/python3.7/ssl.py", line 1216, in wrap_socket
    context.load_cert_chain(certfile, keyfile)
FileNotFoundError: [Errno 2] No such file or directory

If I comment out Step 9, then re-build and exec into the container I can see the following files:

root@8eef51287e5b:/# ls -l /tmp/https.py 
-rw-r--r-- 1 root root 504 Feb 17 15:53 /tmp/https.py
root@8eef51287e5b:/# ls -l /etc/nginx/certs/
total 8
-rw-r--r-- 1 root root 1903 Jan 21 16:23 cert.pem
-rw------- 1 root root 1704 Jan 21 16:23 privkey.pem

Why am I getting a FileNotFoundError?

Upvotes: 0

Views: 3418

Answers (1)

Arnold Vialfont
Arnold Vialfont

Reputation: 91

This error happened to me while the Dockerfile was under a bad format (Windows, including carriage retrun + line feed) so that the code was not read properly after a docker-compose command.

It disappeared when I changed the file format with Notepad++ switcching from Windows (CR LF) to Unix (LF). This can be done in the lower banner next to the text format indicating UTF-8 for exemple.

Upvotes: 1

Related Questions