Simple question, I want to run docker command in background.
(Actually running any command with command line parameters under Powershell is my real question, but docker
is a simple concrete one)
I have a command
docker run -ti --rm -e DISPLAY=$DISPLAY firefox
which runs fine under Powershell, but it blocks.
I want to runs the equivalent method of doing "&" as under *nix:
docker run -ti --rm -e DISPLAY=$DISPLAY firefox &
I've tried
- Run exe in background
- Powershell equivalent of bash ampersand (&) for forking/running background processes
but neither works for me:
> ping google.com &
At line:1 char:17
+ ping google.com &
+ ~
The ampersand (&) character is not allowed.
> Start-Process "C:\Program Files\Docker\Docker\resources\bin\docker.exe" run -ti --rm -e DISPLAY=$DISPLAY firefox
Start-Process : Parameter cannot be processed because the parameter name 'e' is ambiguous. Possible
matches include: -ErrorAction -ErrorVariable.
At line:1 char:86
+ ... Files\Docker\Docker\resources\bin\docker.exe" run -ti --rm -e DISPLAY ...
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.StartProcessCommand
Tried to wrap the whole command within Start-Process { ... }
doesn't work either.
[UPDATE/Summary]
The accepted answers works (after I removed "-ti
" from the command line), as @nischay goyal has put, "please don't use -it as it opens the terminal and blocks it.". The error I got was:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
+ CategoryInfo : NotSpecified: (the input devic...d with 'winpty':String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : localhost
So
Start-Job
might not fit as a general purpose way of doing "&
", e.g., if I want to startbash &
that way.However, the
Start-Process
works after passing all the rest ofdocker
command line parameters to the-ArgumentList
parameter as a single string.And of course, like all docker/Linux camp people say, use
-d
.
All in all, there are many ways to solve the problem. Pick the one that suits you.