docker-machine 中 awk 的意外行为
Unexpected behaviour from awk in docker-machine
受到 this post 的启发,我试图在我的 Mac 上使用 docker-machine
来停止 运行ning 容器。但是,awk
在 docker-machine ssh
中的行为似乎与 运行 直接 "in" 容器时的行为不同。
当我直接通过 ssh 连接到容器时,一切都按预期工作:
me@myMac:~$ docker-machine ssh default
docker@default:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
028fd7148881 myrepo/mycontainer "apachectl -DFOREGROU" 14 minutes ago Up 14 minutes 0.0.0.0:80->80/tcp gloomy_mayer
docker@default:~$ docker ps | awk 'NR > 1 {print }'
028fd7148881
docker@default:~$ docker ps | awk 'NR > 1 {print }' | xargs --no-run-if-empty docker kill
028fd7148881
docker@default:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
但是当 运行 远程时,awk
表现不同:
me@myMac:~$ docker-machine ssh default "docker ps"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7927b10b8a28 myrepo/mycontainer "apachectl -DFOREGROU" 11 seconds ago Up 10 seconds 80/tcp happy_wozniak
me@myMac:~$ docker-machine ssh default "docker ps | awk 'NR > 1 {print }'"
7927b10b8a28 myrepo/mycontainer "apachectl -DFOREGROU" About a minute ago Up About a minute 80/tcp happy_wozniak
me@myMac:~$ docker-machine ssh default "docker ps | awk 'NR > 1 {print }' | xargs --no-run-if-empty docker kill"
7927b10b8a28
Failed to kill container (myrepo/mycontainer): Error response from daemon: Cannot kill container myrepo/mycontainer: No such container: myRepo/myContainer
Failed to kill container (apachectl -DFOREGROU): Error response from daemon: Cannot kill container apachectl -DFOREGROU: No such container: apachectl -DFOREGROU
Failed to kill container (3): Error response from daemon: Cannot kill container 3: No such container: 3
...
为什么 awk
在 docker-machine
下表现不同?
"docker ps | awk 'NR > 1 {print $1}' | xargs --no-run-if-empty docker kill"
$ ==> $
docker ps -q
受到 this post 的启发,我试图在我的 Mac 上使用 docker-machine
来停止 运行ning 容器。但是,awk
在 docker-machine ssh
中的行为似乎与 运行 直接 "in" 容器时的行为不同。
当我直接通过 ssh 连接到容器时,一切都按预期工作:
me@myMac:~$ docker-machine ssh default
docker@default:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
028fd7148881 myrepo/mycontainer "apachectl -DFOREGROU" 14 minutes ago Up 14 minutes 0.0.0.0:80->80/tcp gloomy_mayer
docker@default:~$ docker ps | awk 'NR > 1 {print }'
028fd7148881
docker@default:~$ docker ps | awk 'NR > 1 {print }' | xargs --no-run-if-empty docker kill
028fd7148881
docker@default:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
但是当 运行 远程时,awk
表现不同:
me@myMac:~$ docker-machine ssh default "docker ps"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7927b10b8a28 myrepo/mycontainer "apachectl -DFOREGROU" 11 seconds ago Up 10 seconds 80/tcp happy_wozniak
me@myMac:~$ docker-machine ssh default "docker ps | awk 'NR > 1 {print }'"
7927b10b8a28 myrepo/mycontainer "apachectl -DFOREGROU" About a minute ago Up About a minute 80/tcp happy_wozniak
me@myMac:~$ docker-machine ssh default "docker ps | awk 'NR > 1 {print }' | xargs --no-run-if-empty docker kill"
7927b10b8a28
Failed to kill container (myrepo/mycontainer): Error response from daemon: Cannot kill container myrepo/mycontainer: No such container: myRepo/myContainer
Failed to kill container (apachectl -DFOREGROU): Error response from daemon: Cannot kill container apachectl -DFOREGROU: No such container: apachectl -DFOREGROU
Failed to kill container (3): Error response from daemon: Cannot kill container 3: No such container: 3
...
为什么 awk
在 docker-machine
下表现不同?
"docker ps | awk 'NR > 1 {print $1}' | xargs --no-run-if-empty docker kill"
$ ==> $
docker ps -q