Attaching to Docker Minecraft Container

yottabit

Contributor
Joined
Apr 15, 2012
Messages
192
I successfully deployed itzg/minecraft-bedrock-server.

I can grab the container ID from docker ps --no-trunc.

I do notice there are always two returned; the POD and what appears to be a container in the POD.
  • The POD has a command of /pause
  • The other has a command of /usr/local/bin/entrypoint-demoter --match /data --debug --stdin-on-term stop /opt/bedrock-entry.sh
So when I use docker attach <container_id>, I do see the Minecraft server console output like I would expect:

Code:
[INFO] Running AutoCompaction...
time="2021-09-18T19:41:46Z" level=debug msg="Forwarding signal" signal="window changed"
[INFO] Player connected: <redacted>, xuid: <redacted>


But I can't issue commands in this console like all the guides say I should be able to do. I also can't exit the attachment with Ctrl+P Ctrl+Q (it shows ^P and that's all). Using Ctrl+C exits, but also restarts the container as expected.

Anyone have any ideas about accessing the Minecraft console in the container properly?

Also, I have noticed that it seems only the "owner" of a world can toggle server settings, so even though I've added his XUID as Op permission in the json file, he still cannot toggle these settings. And I'm unable to figure out how to "promote" him to the owner of the world that was created on the server instance. I'm hoping having console access will be enough to manipulate these settings.
 

yottabit

Contributor
Joined
Apr 15, 2012
Messages
192
After some research, it seems most likely to me that the docker container is not instantiated with the -it that allows for attaching an interactive terminal.

Does anyone know how to add this option to the settings in the Apps section? I have tried adding it in Container Entrypoint -> Configure Container Args, but that didn't work.

Any ideas how to control the arguments used to instantiate (docker run ...) the docker container?

Update: it does appear that the supplied docker compose config sets stdin_open: true and tty: true, which sounds to me like the same -it option that would be used in docker run -it .... But I have no idea if this compose file is used in SCALE apps.

Update 2: it also appears there is a Kubernetes config that sets tty: true and stdin: true. But again, not sure if this is used.
 
Last edited:

Kris Moore

SVP of Engineering
Administrator
Moderator
iXsystems
Joined
Nov 12, 2015
Messages
1,448
After the docker container is running I usually attach with "docker exec -it <docker name> /bin/bash".

If you are starting the container through the Apps/K3's interface, there is also this command:

# k3s kubectl exec --namespace ix-minecraft minecraft-XXXX-XXXX -i -t -- /bin/bash

Where you replace ix-minecraft and minecraft-XXXX-XXXX with your instance values.

You can see what is running with k3s kubectl get pods,svc,daemonsets,deployments,statefulset,sc,pvc,ns,job --all-namespaces -o wide
 

yottabit

Contributor
Joined
Apr 15, 2012
Messages
192
Thanks for the hints. I think I'm getting closer.

In my case, I don't want to run bash in the container (but have successfully with the docker exec command), but I want to attach to the running service, which provides an interactive console. That's why I need to use attach instead of exec, and redirect stdin. (I have successfully attached to the docker container with the running process and see the console log output, but since I cannot interact, I'm assuming this is because I need to connect through k3s/kubectl instead of docker directly.)

Using k3s kubectl attach --help, I see this example that seems to be what I need:
Code:
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
# and sends stdout/stderr from 'bash' back to the client
kubectl attach mypod -c ruby-container -i -t


But I cannot figure out how to attach to the container. I've tried many variations of using --namespace and -c, but still haven't figured it out, even with:
Code:
#
k3s kubectl get pods --all-namespaces -o wide
NAMESPACE                           NAME                                                      READY   STATUS    RESTARTS   AGE     IP             NODE         NOMINATED NODE   READINESS GATES
kube-system                         openebs-zfs-node-z2kff                                    2/2     Running   4          7d16h   172.16.42.26   ix-truenas   <none>           <none>
kube-system                         coredns-7448499f4d-8j82c                                  1/1     Running   2          7d16h   172.17.0.105   ix-truenas   <none>           <none>
kube-system                         openebs-zfs-controller-0                                  5/5     Running   10         7d16h   172.17.0.106   ix-truenas   <none>           <none>
ix-yottaplex                        yottaplex-76945fd6bd-lfdlp                                1/1     Running   0          5d16h   172.16.42.26   ix-truenas   <none>           <none>
ix-mcbe1                            mcbe1-ix-chart-7bdc5db565-8ppf4                           1/1     Running   1          40h     172.17.0.122   ix-truenas   <none>           <none>
ix-mcbe-210918-survival-challenge   mcbe-210918-survival-challenge-ix-chart-5f7d8f7c9-4rk5n   1/1     Running   0          20h     172.17.0.129   ix-truenas   <none>           <none>


But I can't figure out exactly what to use for the <mypod> and <ruby-container> values:
Code:
# k3s kubectl attach mcbe-210918-survival-challenge-ix-chart-5f7d8f7c9-4rk5n -i -t
Error from server (NotFound): pods "mcbe-210918-survival-challenge-ix-chart-5f7d8f7c9-4rk5n" not found
# k3s kubectl --namespace ix-mcbe-210918-survival-challenge attach mcbe-210918-survival-challenge-ix-chart-5f7d8f7c9-4rk5n -i -t
error: Unable to use a TTY - container ix-chart did not allocate one
If you don't see a command prompt, try pressing enter.
Error from server: error dialing backend: dial tcp: lookup ix-truenas: no such host


I think I'm so close, but am missing something...
 
Last edited:

llepe

Cadet
Joined
Oct 18, 2021
Messages
3
Where you able to fix this?

I'm facing exactly the same problem and stuck exactly in the same place.
 

yottabit

Contributor
Joined
Apr 15, 2012
Messages
192
I was able to work around it, but not solve it directly. I have not had any more time to mess with kubectl yet, nor search/post about the `ix-truenas: no such host` message that is likely causing my problem.

My workaround was just to manipulate the json files directly in the persistent volumes such that my kids are ops in the games and can control with /slash commands directly from the game frontend.

Maybe in another weekend or two I can get back to troubleshooting this again. If you would like to pick up the torch on the `ix-truenas: no such host` issue, I suggest that's where to start. Please keep me in the loop if you do.

Edit: or the problem is `error: Unable to use a TTY - container ix-chart did not allocate one` ... that seems an even more likely candidate.
 

llepe

Cadet
Joined
Oct 18, 2021
Messages
3
I was doing an independent debugging and got exactly to the same place you did.

I think I'll implement your fix and (same as you) pick up the debug later.

Thanks a lot!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
think I'm so close, but am missing something...
What you were missing was following the instructions that Kris gave you...

# k3s kubectl exec --namespace ix-minecraft minecraft-XXXX-XXXX -i -t -- /bin/bash

...


k3s kubectl --namespace ix-mcbe-210918-survival-challenge attach mcbe-210918-survival-challenge-ix-chart-5f7d8f7c9-4rk5n -i -t
That's not what he said to do...

you needed to use:
k3s kubectl exec --namespace ix-mcbe-210918-survival-challenge mcbe-210918-survival-challenge-ix-chart-5f7d8f7c9-4rk5n -i -t -- /bin/bash
 

llepe

Cadet
Joined
Oct 18, 2021
Messages
3
I was able to work around it, but not solve it directly. I have not had any more time to mess with kubectl yet, nor search/post about the `ix-truenas: no such host` message that is likely causing my problem.

My workaround was just to manipulate the json files directly in the persistent volumes such that my kids are ops in the games and can control with /slash commands directly from the game frontend.

Maybe in another weekend or two I can get back to troubleshooting this again. If you would like to pick up the torch on the `ix-truenas: no such host` issue, I suggest that's where to start. Please keep me in the loop if you do.

Edit: or the problem is `error: Unable to use a TTY - container ix-chart did not allocate one` ... that seems an even more likely candidate.

You had me thinking and I solved this by logging into the server and the looking into the logs:

1634737582602.png

This gave me my own XUID and then as per the documentation here: itzg/minecraft-bedrock-server I added the Environmental variable OPS with my XUID and saved this. (This reloaded the container).

1634737452389.png


When I re-logged into the minecraft server I was an OP, problem solved :)

I was not able to attach myself to the container, but I actually solved my problem.

Thanks for your help!
 
Top