Connecting to the running Server
Hi, great work! I was wondering if after starting the docker container as a background process there is any way to access the shell again? Normally if I run it without setting it to run in the background I can enter commands like "save", "exit", and "kick", and I would like to be able to use this access without having to have it running in the foreground the whole time.
So as an update, before asking my question, I thought that docker attach was what I was looking for, but when I used it, I just got a blank console, so I was confused. Now I tried again, and then logged into the server with Terraria, and realized that I actually am getting the server output, but I can't enter any commands:
$ sudo docker attach terraria
help
exit
<ip address> is connecting...
Debug: GetDataHandlers / HandlePlayerBuffList handled event and sent data <Username>
<Username> has joined.
So help and exit did nothing, but I saw all of the server info. Is there any way that I could enter commands here?
You can detach from an interactive Docker session without exiting the container. You “daemonize” the container. The effect will be, as if you had started it with the -d flag in the first place.
You have to use two combinations, one after the other: ctrl+p followed by ctrl+q. You turn interactive mode to daemon mode, which keeps the container running but frees up your terminal.
You can attach to it later using docker attach, if you need to interact with the container more. From: https://vsupalov.com/exit-docker-container/
So the idea is you start in interactive mode with sudo docker run -it -p 7777:7777 -v $HOME/terraria/world:/root/.local/share/Terraria/Worlds --name="tshock" --log-opt max-size=200k ryshe/terraria:latest, detach using Ctrl+P and Ctrl+Q, then access it back again with sudo docker attach tshock.
Personally, this should be in documentation since not everyone is too familiar with docker, but it is what it is.