3

I found this instruction on piping commands in Windows CMD:

The "pipe" redirects the output of a program or command to a second program or command.

Syntax:

Command1 | Command2

[Source] (at the very bottom)

Yet docker ps -aq | docker start or any similar combination just returns errors.

The only working combination to start all stopped container works in PowerShell.

docker start $(docker ps -a -q -f "status=exited")
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
MattJ
  • 683
  • 2
  • 10
  • 35
  • 1
    Powershell isn't quite the same as cmd. What errors, exactly, do you get? – vonPryz Jun 01 '17 at 08:06
  • Yeap, I understand its just that I do most of my work through CMD, turning on powershell each time I need docker seems cumbersome. I get '"dokcer start" requires at least 1 argument.' -> docker ps -aq | docker start – MattJ Jun 01 '17 at 10:11
  • The error message suggests that the docker program does not read from stdin and must have explicit command line parameters specified. – lit Jun 01 '17 at 13:41

1 Answers1

6

You can pipe into docker containers (-i), but you can't pipe arguments to the docker command itself.

In PowerShell use a loop for starting a list of stopped containers:

docker ps -a -q -f "status=exited" | ForEach-Object { docker start $_ }

In CMD use a loop for starting a list of stopped containers:

for /f "tokens=*" %i in ('docker ps -a -q -f "status=exited"') do docker start %i
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328