Hello, this is haniokasai. When docker attach with Docker, only pid 1 can be operated interactively. [^ 1] Usually that's not a problem, but I'm in trouble. In my container the Dockerfile calls a shell script, which runs PHP CGI. In that case, php's pid is not 1, so there is no way to enter it. (You can see the output with attach.) So I entered it directly into stdin.
Caution You can do docker attach, but don't make it interactive. If so, stdin returns "Text file busy" and does not hold. When attaching, do as follows. (In this case, attach does not receive stdin. You can choose either attach or direct file input.)
attach
docker -H DOCKERHOST attach container name--no-stdin
First, check the pid of the standard input destination on top.
# docker top zzzzzzzz_container
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                25312               25287               0                   16:09               ?                   00:00:00            /bin/sh -c sh /minecraft/resources/run-Main.sh
root                25366               25312               0                   16:10               ?                   00:00:00            sh /minecraft/resources/run-Main.sh
root                25434               25366               0                   16:10               ?                   00:00:00            sh /minecraft/resources/run-BE-BDS.sh
root                25472               25434               13                  16:10               ?                   00:14:22            /minecraft/bin/bedrock_server
Execute standard input with a command
# echo "help" > /proc/25472/fd/0
If you type help into bedrock_server as standard, help will be returned properly.
# docker logs zzzzzzzz_container --tail=10
[2019-12-15 08:09:39 INFO] Player disconnected: hanicraft, xuid: 2535460621431466
§2--- Showing help page 1 of 18 (/help <page>) ---
/? [command: CommandName]
/? <page: int>
/alwaysday [lock: Boolean]
/changesetting allow-cheats <value: Boolean>
/changesetting difficulty <value: Difficulty>
/changesetting difficulty <value: int>
/clear [player: target] [itemName: Item] [data: int] [maxCount: int]
§2Tip: Use the <tab> key while typing a command to auto-complete the command or its arguments
Create source container
docker create --name container name--memory=3500mb --network="host" --storage-opt size=2G  --cap-add SYS_PTRACE  -v /proc:/newproc:ro
The point of interest is
--Add SYS_PTRACE authority --Mount / proc on host as / newproc read-only
The rest is the same as before.
In the container
# echo "help" > /newproc/25472/fd/0
I made it with @itsu_dev. It will be interesting because Itsukun scrapes the top.
https://serverfault.com/questions/178457/can-i-send-some-text-to-the-stdin-of-an-active-process-running-in-a-screen-sessi https://orebibou.com/2016/04/linux%E3%81%A7%E5%8B%95%E4%BD%9C%E4%B8%AD%E3%81%AE%E3%83%97%E3%83%AD%E3%82%BB%E3%82%B9%E3%81%AE%E5%87%BA%E5%8A%9B%E5%86%85%E5%AE%B9%E3%82%92%E3%81%BF%E3%82%8B/
Recommended Posts