A minecraft server with websocket console.
452
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!)
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
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
| ENV | Description | Default | Needed for |
|---|---|---|---|
| TZ | set timezone | Europe/Berlin | install |
| LIMIT_RAM | enable/disable memory limit | true | minecraft |
| MAX_RAM | set max. to use memory | 4G | minecraft |
| MIN_RAM | set min. to use memory | 4G | minecraft |
| JWT_SECURE_STRING | set the secret part of JWT | shh | websocket |
| HTTPS | enable/disable wss (https for websocket) | true | websocket |
| UPNP | enable/disable UPNP (if false you dont need the other upnp ENV) | true | upnp |
| HOST_IP | ip of the docker Host (same Network as the router) | none | upnp |
| IGD_URL | set the url of the upnp (default for FritzBox) | http://192.168.178.1:49000/igddesc.xml | upnp |
| WS_PORT | set the port, that you exposed for websocket | 8080 | upnp |
| MC_PORT | set the port, that you exposed for minecraft server | 25565 | upnp |
| Directory | Description |
|---|---|
| /app/game | here are the game files saved |
| /app/cert | here you have to add your https certificat (cert.pem) and key (key.pem) |
<!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>
holypenguin/ws-minecraft:<minecraft-version>
Content type
Image
Digest
Size
229.3 MB
Last updated
about 5 years ago
docker pull holypenguin/ws-minecraft:1.17.1