Ivan Shelonik
Ivan Shelonik

Reputation: 2028

Docker add all folder files to the existed folder without replacement

How to copy folder files into docker existed folder without file replacement

Example:

locally
|-- demo
|   -- file3.txt
|   -- file4.txt

docker
|-- app
|   -- src
|      -- file1.txt
|      -- file2.txt

It can be done via RUN COPY demo/file3.txt app/src/file3.txt but it's not a great way to workaround it if there are multiple of them.

Upvotes: 1

Views: 2071

Answers (1)

mchawre
mchawre

Reputation: 12268

COPY command should work, no need to specify full path along with the filename while copying.

Here is an example where I want to copy all the files inside demo folder onto /app/src folder of the container.

/ # [node1] (local) [email protected] ~
$ cat Dockerfile 
FROM alpine
RUN mkdir -p /app/src
RUN touch /app/src/file1.txt
RUN touch /app/src/file2.txt
COPY demo/* /app/src/
[node1] (local) [email protected] ~
$ ls demo/
file3.txt   file4.txt   fileabc.sh  filexyz.py
[node1] (local) [email protected] ~
$ docker build -t myimage:v1 .
$
[node1] (local) [email protected] ~
$ docker run -it --rm myimage:v1 ls -ltrh /app/src/
total 0      
-rw-r--r--    1 root     root           0 Aug 17 11:40 file3.txt
-rw-r--r--    1 root     root           0 Aug 17 11:40 file4.txt
-rw-r--r--    1 root     root           0 Aug 17 11:40 file1.txt
-rw-r--r--    1 root     root           0 Aug 17 11:40 file2.txt
-rw-r--r--    1 root     root           0 Aug 17 11:47 filexyz.py
-rw-r--r--    1 root     root           0 Aug 17 11:47 fileabc.sh
[node1] (local) [email protected] ~
$ 

Hope this helps.

Upvotes: 3

Related Questions