I'm running a Dockerfile with two COPY statements as such:
WORKDIR /app
COPY requirements.txt entrypoint.sh ./
COPY binaries/ ./binaries
It works fine, I end up having what I need:
root:/# ls /app
requirements.txt
entrypoint.sh
binaries/
├── executable1
├── executable2
└── executable3
But I'd like to keep the number of layers as low as possible, hence I try to combine the two COPY statements into one:
WORKDIR /app
COPY requirements.txt entrypoint.sh binaries/ ./
But this is 'extracting' all the files from the binaries/ folder and lay them next to the 2 others:
root:/# ls /app
requirements.txt
entrypoint.sh
executable1
executable2
executable3
Question
How do you combine both some files and one (or more) specific folder(s) into one unique COPY statement in a Dockerfile (if it's possible of course)?
Environment information:
Docker version 20.10.0, build 7287ab3
Host: ubuntu 18.04.5
Testing MWE
From localhost:~$
mkdir -p doc && cd doc && mkdir -p binaries && touch entrypoint.sh \
requirements.txt binaries/ex1 binaries/ex2 binaries/ex3 \
&& echo 'FROM debian:buster-slim
WORKDIR /app
COPY requirements.txt entrypoint.sh binaries ./' >> Dockerfile
From localhost:~$
docker build --no-cache -t test:latest . \
&& docker run -it --rm --name test test:latest bash
From inside container:
root:/app# ls
gives me:
entrypoint.sh ex1 ex2 ex3 requirements.txt
The same behaviour is encountered when using ADD instead of COPY.