Sign inSign up

holypenguin/ws-minecraft

By holypenguin

•Updated about 5 years ago

A minecraft server with websocket console.

Image
0

452

holypenguin/ws-minecraft repository overview

⁠WS-Minecraft Docker

⁠What is this?

The WS-Minecraft Docker is a Docker with a Minecraft Server and a websocket to the console and build in upnp to auto open the needed Ports. For example, if you want to create your own Minecraft-Consol-Website, you can use this Docker. (https://holypenguin.de/⁠ uses this too!)

⁠How does it work?

If you run the Docker on Port 8080 (for the websocket) and the port 25565 (for minecraft), both will be exposed to the Internet. Now you are able to connect to the MC-Server and to connect to the websocket. Every message that the websocket received will be automatically forwarded to the minecraft server and everthing that the server displays, will be displayed on the website using the websocket.

If you want to start/stop/restart/save the server, send a JSON with the command value to the websocket. Example:

> {"command": "start"}
> {"command": "stop"}
> {"command": "restart"}
> {"command": "save"}

To make sure, that the user is authorized we use JWT (jsonwebtoken).

To safely close the docker use:

> docker container exec -it <container-name> sh -c ./stop.sh

⁠IMPORTENT

If you want to run this on a Raspberry Pi run on the Pi first:

> wget http://ftp.us.debian.org/debian/pool/main/libs/libseccomp/libseccomp2_2.5.1-1_armhf.deb
> sudo dpkg -i libseccomp2_2.5.1-1_armhf.deb
⁠Environement Variables
ENVDescriptionDefaultNeeded for
TZset timezoneEurope/Berlininstall
LIMIT_RAMenable/disable memory limittrueminecraft
MAX_RAMset max. to use memory4Gminecraft
MIN_RAMset min. to use memory4Gminecraft
JWT_SECURE_STRINGset the secret part of JWTshhwebsocket
HTTPSenable/disable wss (https for websocket)truewebsocket
UPNPenable/disable UPNP (if false you dont need the other upnp ENV)trueupnp
HOST_IPip of the docker Host (same Network as the router)noneupnp
IGD_URLset the url of the upnp (default for FritzBox)http://192.168.178.1:49000/igddesc.xml⁠upnp
WS_PORTset the port, that you exposed for websocket8080upnp
MC_PORTset the port, that you exposed for minecraft server25565upnp
⁠Directorys
DirectoryDescription
/app/gamehere are the game files saved
/app/certhere you have to add your https certificat (cert.pem) and key (key.pem)
⁠Example index.html
    <!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
      </head>

      <!-- Form to submit the commands -->
      <body>
        <div id="test">
        </div>
        <input type="text" id="code" name="test" />
        <button name="submit" onclick="sendMessage()">Submit</button>
      </body>

      <!-- Script Part -->
      <script type="text/javascript">
          // Create WebSocket-Connection
          const socket = new WebSocket('ws://localhost:8080')

          // Events happend on finished connection
          socket.addEventListener('open', function (event) {
          })

          // Events happend if get message from Server
          socket.addEventListener('message', function (event){
            // Insert message to HTML
            document.getElementById('test').innerHTML += "<br>" + event.data
          })

          // Function to send command
          async function sendMessage(){
            let message = document.getElementById('code').value
              socket.send(message)
          }
      </script>
  </html>

⁠Tags:

holypenguin/ws-minecraft:<minecraft-version>

Tag summary

Content type

Image

Digest

Size

229.3 MB

Last updated

about 5 years ago

docker pull holypenguin/ws-minecraft:1.17.1