Reputation: 3769
I have a very simple dockerfile which i have written but unfortunately, it is failing while executing below command in dockerfile:-
RUN ["cp -r", "node_modules/dir1/test/*", "/app"]
Below is the Error message which i get:-
OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"cp -r\": executable file not found in $PATH": unknown
I have also tried using "mv" command instead of "cp" but with no success.
I don't want to move the complete folder but all the content of folder. As said if i execute below command it works but, it moves the directory:-
RUN ["cp -r", "node_modules/dir1/test", "/app"]
Any Suggestions.? I have tried looking into many questions but, couldnt find a concrete explanation and the answer on how we can do it.?
Thanks, Vishesh.
Upvotes: 0
Views: 1465
Reputation: 159732
Internally in Unix-like operating systems, commands are broken up into "words". When you use the JSON-array syntax for RUN
, ENTRYPOINT
, and CMD
directives, you're explicitly specifying what the words are, and they're not further processed split up.
In particular when you run
RUN ["cp -r", "node_modules/dir1/test/*", "/app"]
it looks for a command named cp -r
in the usual places, where the command name includes a space and a hyphen. It won't find /bin/cp
which doesn't have a space and a hyphen and there isn't a /bin/cp\ -r
. If this were to work, it would also pass its first argument containing a *
in the filename, which will also fail.
The easiest solution here is to not use the JSON-array form. This will implicitly run a shell (the command is wrapped in /bin/sh -c
) which will split words and expand globs for you.
RUN cp -r node_modules/dir1/test/* /app
If you didn't need the wildcard, you need to manually split cp
and -r
into separate words
RUN ["cp", "-r", "node_modules/dir1/test", "/app"]
Upvotes: 1
Reputation: 2462
First, you need to check if the cp
command is available. Once it's available you need to add /.
for copying the content only.
RUN ["cp -r", "node_modules/dir1/test/.", "/app/"]
Snapshot from the documentation.
Upvotes: 1