"Cannot create directory ... no such file or directory"

19,243

cp will report that error if the parent directory (www in this case) does not exist:

$ mkdir src dest
$ touch src/file
$ cp -r src dest/www/html/
cp: cannot create directory ‘dest/www/html/’: No such file or directory

as opposed to:

$ mkdir -p dest/www/html
$ cp -r src dest/www/html/
$ find dest
dest
dest/www
dest/www/html
dest/www/html/src
dest/www/html/src/file

Also, I believe your:

RUN cp 775 -rf roundcubemail-1.2.3/. /var/www/html/

command is potentially a reference to the install -m command, which accepts a MODE to set on copied files. cp, on the other hand, is simply expecting a list of source directories, and so that command is looking for three files/directories to copy to /var/www/html/:

  1. 755
  2. -rf
  3. roundcubemail-1.2.3

To solve this particular issue, I would recommend adding this to your Dockerfile:

RUN mkdir -p /var/www/html
Share:
19,243

Related videos on Youtube

Ora nge
Author by

Ora nge

Just a frontend dev loving Vue3.

Updated on September 18, 2022

Comments

  • Ora nge
    Ora nge almost 2 years

    When executing the dockerfile, the command RUN cp -rf roundcubemail-1.2.3/. /var/www/html/ is executed and I'm getting the following error:

    cp: cannot create directory '/var/www/html/': No such file or directory
    ERROR: Service 'mailserver' failed to build: The command '/bin/sh -c cp -rf 
    roundcubemail-1.2.3/. /var/www/html/' returned a non-zero code: 1
    

    That error occurs when executing any command on that directory. I already changed the permissions to 775, but that didn't change anything.

    When adding 775 to RUN cp 775 -rf roundcubemail-1.2.3/. /var/www/html/ the error changes to "is not a directory".

    • JShorthouse
      JShorthouse about 5 years
      I assume this is a Docker question? If it is, can you specify that in your question and post your Dockerfile?
    • roaima
      roaima about 5 years
      /var/www/html exists and is a directory?
    • Kusalananda
      Kusalananda about 5 years
      The commands are run using sh -c, which means the command possibly has to be quoted.
    • Ora nge
      Ora nge about 5 years
      @roaima Yes i checked it with [ -d "/path/to/dir" ]
    • Jeff Schaller
      Jeff Schaller about 5 years
      inside the container, though? cp will report that error if the /var/www does not exist
    • Ora nge
      Ora nge about 5 years
      @JeffSchaller How to chek if it's inside the container?
    • roaima
      roaima about 5 years
      Actually, given the cp command, just /var/www needs to exist (as a directory). It'll create html if necessary, but not complain if it already exists.
    • Ora nge
      Ora nge about 5 years
      @roaima So any idea how to solve that?
  • Ora nge
    Ora nge about 5 years
    what are src and dest for?
  • Jeff Schaller
    Jeff Schaller about 5 years
    I didn't feel like clobbering my existing /var/www/html directory to test, so those are just example directories to demonstrate the behavior (and the solution).
  • roaima
    roaima about 5 years
    In your example, if you change the source from src to src/. it will either use the existing target or create it. See How to copy a folder recursively in an idempotent way using cp.
  • Ora nge
    Ora nge about 5 years
    So I need to add a ' RUN mkdir -p var/www/html RUN cp -r src/ var/www/html/ ' in front of the other commands?
  • Ora nge
    Ora nge about 5 years
    Alright, thank you. I'll test this tomorrow. :)