dfsg76
dfsg76

Reputation: 524

Docker copy doesn't seem to work with stopped container and wildcard

I'm building a maven project inside a docker container:

docker run build-image "mvn clean package -f ./pom.xml"

The source and workdir in the Dockerfile for "build-image" are located at /src/ (having two subfolders with each containing one submodule with pom.xml, parent pom at /src/pom.xml)

When the build is finished, the container exits. Then, I want to extract the build artifacts:

docker cp <container-id>:/src/module1/target/*.war ./

I get an error:

Error response from daemon: Could not find the file /src/<module1>/target/*.war in container silly_nobel

When I specify the file without using the wildcard:

docker cp <container-id>:/src/<module1>/target/<module1>##0.1.0-SNAPSHOT.war ./

it succeeds..

Is this intended behaviour or a bug? I googled a bit but could not find a similar post with that problem. docker version is 18.02.0-ce, build fc4de44

Best regards

Upvotes: 0

Views: 274

Answers (1)

adebasi
adebasi

Reputation: 3945

docker cp does not support wildcards at the moment (github discussion)

But you can get what you want by using multi stage builds. In multi stage builds you can use COPY which allows wildcards. This is a short example:

FROM alpine as builder
RUN touch foo.txt
RUN touch bar.txt


FROM alpine
COPY --from=builder /*.txt ./

Build an run image:

$ docker build -t foobar .
$ docker run foobar ls
bar.txt
bin
dev
etc
foo.txt
...

Upvotes: 1

Related Questions