'Docker cp' with parameter expansion (PowerShell)

281 views Asked by At

I want to copy a directory into a docker container, which is only defined by a certain query. I tried this:

docker cp ../from-here/. $(docker ps -aqf "name=my-ending$"):/to-here

Unforunately this throws this error:

"docker cp" requires exactly 2 arguments.

Running the same command with pasting the real Container ID works.

It seems, that PowerShell in combination with Docker doesn't allow parameter expansion.

Is there an easy work around for this problem in a single line?

2

There are 2 answers

0
nilosch On BEST ANSWER

This works:

docker @("cp", "../from-here/.", "$(docker ps -aqf "name=my-ending$"):/to-here")
2
ozs On

in power shell you need to use | (pipe) to continue commands

docker cp ../from-here/. | % {docker ps -aqf "name=my-ending$"}:/to-here