Docker获取服务任务之一的实时日志

时间:2022-04-16 03:54:40

I can't ssh into docker manager and get service logs. I get "docker service logs" requires exactly 1 argument. error, when I ssh into my manager with

我不能ssh到docker manager并获取服务日志。我得到“docker service logs”只需要1个参数。错误,当我ssh到我的经理与

docker-machine ssh manager1

and run

docker logs --follow $(docker ps | grep redis |  head -n1 | cut -d " " -f1)

everything works, but when I run the following command I get "docker service logs" requires exactly 1 argument.

一切正常,但是当我运行以下命令时,我得到“docker service logs”只需要1个参数。

docker-machine ssh manager1 "docker service logs $(docker ps | grep redis |  head -n1 | cut -d ' ' -f1) --follow"

how can I ssh into manager1 and pass the command to run?

我怎样才能进入manager1并传递命令来运行?

1 个解决方案

#1


0  

docker ps has some filtering and output options that mean awk/grep etc are rarely needed.

docker ps有一些过滤和输出选项,意味着很少需要awk / grep等。

docker-machine ssh manager1 sh -uexc 'echo; 
  cid=$(docker ps -q -f ancestor=redis -l); 
  docker service logs -f $cid || echo cid[$cid]'

docker ps options.

docker ps选项。

--filter , -f       Filter output based on conditions provided
--format            Pretty-print containers using a Go template
--last , -n         Show n last created containers (includes all states)
--latest , -l       Show the latest created container (includes all states)

#1


0  

docker ps has some filtering and output options that mean awk/grep etc are rarely needed.

docker ps有一些过滤和输出选项,意味着很少需要awk / grep等。

docker-machine ssh manager1 sh -uexc 'echo; 
  cid=$(docker ps -q -f ancestor=redis -l); 
  docker service logs -f $cid || echo cid[$cid]'

docker ps options.

docker ps选项。

--filter , -f       Filter output based on conditions provided
--format            Pretty-print containers using a Go template
--last , -n         Show n last created containers (includes all states)
--latest , -l       Show the latest created container (includes all states)