2

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".

  • I assume this is a Docker question? If it is, can you specify that in your question and post your Dockerfile? – JShorthouse Apr 9 at 13:49
  • 1
    /var/www/html exists and is a directory? – roaima Apr 9 at 13:55
  • The commands are run using sh -c, which means the command possibly has to be quoted. – Kusalananda Apr 9 at 13:56
  • @roaima Yes i checked it with [ -d "/path/to/dir" ] – Ora nge Apr 9 at 13:57
  • 1
    inside the container, though? cp will report that error if the /var/www does not exist – Jeff Schaller Apr 9 at 13:58
2

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
  • what are src and dest for? – Ora nge Apr 9 at 14:08
  • 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). – Jeff Schaller Apr 9 at 14:08
  • 1
    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. – roaima Apr 9 at 14:09
  • 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 Apr 9 at 14:10
  • @Orange I've updated the post with more description and a suggestion for solving the problem – Jeff Schaller Apr 9 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.