0

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?

nilosch
  • 143
  • 1
  • 7

2 Answers2

1

This works:

docker @("cp", "../from-here/.", "$(docker ps -aqf "name=my-ending$"):/to-here")
nilosch
  • 143
  • 1
  • 7
0

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

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

ozs
  • 3,051
  • 1
  • 10
  • 19
  • Throws the following: `+ CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException` `+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand` – nilosch Dec 01 '20 at 15:28
  • what about using for-each: Foreach ($docker_container_name in (docker ps -aq)) { $cp_arguments = @("cp","/from_here","$($docker_container_name):/to_here") docker $cp_arguments } – ozs Dec 01 '20 at 15:52