gpt4 book ai didi

awk - 来自 docker-machine 中 awk 的意外行为

转载 作者:行者123 更新时间:2023-12-03 17:37:53 25 4
gpt4 key购买 nike

灵感来自 this post ,我正在尝试使用 docker-machine在我的 Mac 上停止正在运行的容器。然而,awkdocker-machine ssh 中的行为似乎有所不同比直接“在”容器中运行时。

当我直接通过 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 $1}'
028fd7148881
docker@default:~$ docker ps | awk 'NR > 1 {print $1}' | 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 $1}'"
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 $1}' | 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
...

为什么 awkdocker-machine 下表现不同?

最佳答案

"docker ps | awk 'NR > 1 {print \$1}' | xargs --no-run-if-empty docker kill"


$ ==> \$

docker ps -q

关于awk - 来自 docker-machine 中 awk 的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com