简体   繁体   English

Docker:在容器中运行的 spigot 控制台上执行命令

[英]Docker: Exec a command on spigot console runnning in a container

To summarize the problem I have: I want to execute a command on the minecraft console that is running in the container like when I attach to it in interactive mode but without the need to attach to it.总结一下我遇到的问题:我想在容器中运行的我的世界控制台上执行一个命令,就像我以交互模式附加到它但不需要附加到它一样。

docker attach container_name

command

detach_from_contaienr

Like running docker exec but it puts the command into the stdin of the programm that is running inside the container like in docker attach.就像运行 docker exec 一样,但它将命令放入在容器内运行的程序的标准输入中,就像在 docker 附加中一样。

I simply search a oneliner that does the same.我只是搜索一个做同样事情的oneliner。 Like in this question就像在这个问题

Edit: echo 'say test' | docker attach <container id>编辑: echo 'say test' | docker attach <container id> echo 'say test' | docker attach <container id>

Gives the Error:给出错误:

the input device is not a TTY

Edit2: after removing the -t flag on the container linke in this post Edit2:在这篇文章中删除容器链接上的 -t 标志后

echo 'say test' | docker attach <container id>

the command gets to the server as the log reveales but after executing that I am stuck in a blank input because the command doesn't stop somehow该命令在日志显示时到达服务器,但在执行后我被困在一个空白输入中,因为该命令不会以某种方式停止

If i now do the double ctrl+c the container stops...如果我现在执行双重 ctrl+c 容器停止...

Edit3: I try to execute these commands on the docker host and execute the command in the running spigot minecraft server Edit3:我尝试在 docker 主机上执行这些命令并在运行的 spigot minecraft 服务器中执行命令

Apparently, you can use a named pipe to do this, as shown here: https://stackoverflow.com/a/26765590/2926055显然,您可以使用命名的 pipe 来执行此操作,如下所示: https://stackoverflow.com/a/26765590/2926055

# in the Docker container
$ mkfifo myfifo
$ java -jar minecraft_server.jar nogui < myfifo

# via your `docker exec`
$ echo 'say test' > myfifo

As noted, be careful you don't accidentally send an EOF character.如前所述,请注意不要意外发送 EOF 字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM