3

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

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Ora nge
  • 193
  • 1
  • 3
  • 11

1 Answers1

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
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • what are src and dest for? – Ora nge Apr 09 '19 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 09 '19 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](https://unix.stackexchange.com/a/228637/100397). – roaima Apr 09 '19 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 09 '19 at 14:10
  • @Orange I've updated the post with more description and a suggestion for solving the problem – Jeff Schaller Apr 09 '19 at 14:12
  • Alright, thank you. I'll test this tomorrow. :) – Ora nge Apr 09 '19 at 14:12