72 lines
29 KiB
HTML
72 lines
29 KiB
HTML
<!doctype html><html lang=en dir=auto><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=robots content="index, follow"><title>Minecraft Server on Docker ⛏ 🐳 | ahmza's ramblings</title>
|
||||
|
|
<meta name=keywords content="Games,Docker,ARM"><meta name=description content="Ever wanted to build a Minecraft server in docker !! Start here"><meta name=author content="ahmza"><link rel=canonical href=https://blog.ahmza.com/Page%28/posts/minecraft-server-on-docker.md%29><link crossorigin=anonymous href=/assets/css/stylesheet.cea311b1d5843eeee9ccb805d4520f69aa5e2843db5d66ace5369ce8f1942c0f.css integrity="sha256-zqMRsdWEPu7pzLgF1FIPaapeKEPbXWas5Tac6PGULA8=" rel="preload stylesheet" as=style><script defer crossorigin=anonymous src=/assets/js/highlight.f413e19d0714851f6474e7ee9632408e58ac146fbdbe62747134bea2fa3415e0.js integrity="sha256-9BPhnQcUhR9kdOfuljJAjlisFG+9vmJ0cTS+ovo0FeA=" onload=hljs.initHighlightingOnLoad()></script><link rel=icon href=https://blog.ahmza.com/img/favicon.png><link rel=icon type=image/png sizes=16x16 href=https://blog.ahmza.com/img/favicon.png><link rel=icon type=image/png sizes=32x32 href=https://blog.ahmza.com/img/favicon.png><link rel=apple-touch-icon href=https://blog.ahmza.com/img/favicon.png><link rel=mask-icon href=https://blog.ahmza.com/img/favicon.png><meta name=theme-color content="#2e2e33"><meta name=msapplication-TileColor content="#2e2e33"><noscript><style>#theme-toggle,.top-link{display:none}</style></noscript><script async src="https://www.googletagmanager.com/gtag/js?id=G-HSJHLHP8FZ"></script><script>var doNotTrack=!1;if(!doNotTrack){window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag("js",new Date),gtag("config","G-HSJHLHP8FZ",{anonymize_ip:!1})}</script><meta property="og:title" content="Minecraft Server on Docker ⛏ 🐳"><meta property="og:description" content="Ever wanted to build a Minecraft server in docker !! Start here"><meta property="og:type" content="article"><meta property="og:url" content="https://blog.ahmza.com/posts/minecraft-server-on-docker/"><meta property="og:image" content="https://blog.ahmza.com/webp/posts/mc-docker/feature-anim.webp"><meta property="article:section" content="posts"><meta property="article:published_time" content="2022-05-24T09:33:35+01:00"><meta property="article:modified_time" content="2022-05-24T09:33:35+01:00"><meta property="og:site_name" content="ahmza's ramblings"><meta name=twitter:card content="summary_large_image"><meta name=twitter:image content="https://blog.ahmza.com/webp/posts/mc-docker/feature-anim.webp"><meta name=twitter:title content="Minecraft Server on Docker ⛏ 🐳"><meta name=twitter:description content="Ever wanted to build a Minecraft server in docker !! Start here"><script type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":2,"name":"Posts","item":"https://blog.ahmza.com/posts/"},{"@type":"ListItem","position":3,"name":"Minecraft Server on Docker ⛏ 🐳","item":"https://blog.ahmza.com/posts/minecraft-server-on-docker/"}]}</script><script type=application/ld+json>{"@context":"https://schema.org","@type":"BlogPosting","headline":"Minecraft Server on Docker ⛏ 🐳","name":"Minecraft Server on Docker ⛏ 🐳","description":"Ever wanted to build a Minecraft server in docker !! Start here","keywords":["Games","Docker","ARM"],"articleBody":"Introduction Minecraft is a great game and when it comes to multiplayer, a dedicated server is the way to go (here’s why1). Myself and a few others recently decided to start playing this game again, and I took the opportunity to deploy the server in my lab.\nA Minecraft server does not require a ton of resources to run, However from my experience the more resources you can throw at it the better, especially when you start to introduce mods and more than a few players.\nI run our server on my main PC within WSL and Docker. This allows me to leverage the system resources in my PC 🦾 leaving the Pi Cluster to handle the rest of the stuff in my lab. The only reason I opted to go this route is that I don’t want our server to be limited by hardware resources as well as the Minecraft server effecting the overall performance of the Pis.\nPrerequisites Docker Docker Compo
|
|||
|
|
server is the way to go (here’s why<sup id=fnref:1><a href=#fn:1 class=footnote-ref role=doc-noteref>1</a></sup>). Myself and a few others
|
|||
|
|
recently decided to start playing this game again, and I took the
|
|||
|
|
opportunity to deploy the server in my lab.</p><p>A Minecraft server does not require a ton of resources to run, However
|
|||
|
|
from my experience the more resources you can throw at it the better,
|
|||
|
|
especially when you start to introduce mods and more than a few players.</p><p>I run our server on my main PC within WSL and Docker. This allows me to
|
|||
|
|
leverage the system resources in my PC 🦾 leaving the <a href=https://blog.ahmza.com/posts/building-a-docker-swarm-with-pis/ target=_blank>Pi Cluster</a>
|
|||
|
|
to handle the rest of the stuff in my lab. The only reason I opted to
|
|||
|
|
go this route is that I don’t want our server to be limited by hardware
|
|||
|
|
resources as well as the Minecraft server effecting the overall
|
|||
|
|
performance of the Pis.</p><h2 id=prerequisites><strong>Prerequisites</strong><a hidden class=anchor aria-hidden=true href=#prerequisites>#</a></h2><ul><li>Docker</li><li>Docker Compose</li></ul><h2 id=requirements2><strong>Requirements</strong><sup id=fnref:2><a href=#fn:2 class=footnote-ref role=doc-noteref>2</a></sup><a hidden class=anchor aria-hidden=true href=#requirements2>#</a></h2><h4 id=minimum-1-5-players><strong>Minimum (1-5 Players)</strong><a hidden class=anchor aria-hidden=true href=#minimum-1-5-players>#</a></h4><ul><li>Intel Pentium 4 or AMD Athlon based CPU</li><li>512 MB RAM</li><li>2 GB Storage space</li></ul><h4 id=recommended-10-15-players><strong>Recommended (10-15 Players)</strong><a hidden class=anchor aria-hidden=true href=#recommended-10-15-players>#</a></h4><ul><li>Intel Core or AMD K8 based CPU</li><li>3 GB RAM</li><li>16 GB Storage Space</li></ul><h4 id=optimal-20-players><strong>Optimal (20+ Players)</strong><a hidden class=anchor aria-hidden=true href=#optimal-20-players>#</a></h4><ul><li>Intel i5/i7 or AMD Ryzen 5/7 Based CPU</li><li>6 GB RAM</li><li>35 GB Storage Space</li></ul><h2 id=building-the-container><strong>Building the Container</strong><a hidden class=anchor aria-hidden=true href=#building-the-container>#</a></h2><p>Now we have the formalities sorted, we can get to work on creating the
|
|||
|
|
docker container for Minecraft.</p><ol><li><p><strong>Create a directory in which you will keep the Minecraft server files</strong></p><ul><li><code>mkdir minecraft-server</code></li><li><code>cd minecraft-server</code></li></ul></li><li><p><strong>Create an environment file to be used by the Docker Container</strong></p><ul><li>The <em>.env</em> file allows us to specify variables which we can use
|
|||
|
|
across the build process.</li><li><code>touch .env</code></li><li>Edit the file in a text editor, i.e. vim <code>vim .env</code><div class=highlight><pre tabindex=0 class=chroma><code class=language-bash data-lang=bash><span class=line><span class=cl><span class=nv>CONTAINER_NAME</span><span class=o>=</span>minecraft-server
|
|||
|
|
</span></span><span class=line><span class=cl><span class=nv>SERVER_MEM</span><span class=o>=</span><span class=m>4096</span> <span class=c1>#change this to your desired value (in MB)</span>
|
|||
|
|
</span></span><span class=line><span class=cl><span class=nv>SERVER_JAR</span><span class=o>=</span>minecraft_server.1.18.2.jar
|
|||
|
|
</span></span></code></pre></div></li></ul></li><li><p><strong>Create the docker-compose.yml file</strong></p><ul><li>The <em>docker-compose.yml</em> file specifies the container that we
|
|||
|
|
want to build, outlining the build context (Dockerfile),
|
|||
|
|
setting the variables (from .env), configuring storage volumes
|
|||
|
|
for persistence as well as ports and the container name.</li><li><code>touch docker-compose.yml</code></li><li>Edit the file in a text editor<sup id=fnref:3><a href=#fn:3 class=footnote-ref role=doc-noteref>3</a></sup>, I.e. vim <code>vim docker-compose.yml</code><div class=highlight><pre tabindex=0 class=chroma><code class=language-bash data-lang=bash><span class=line><span class=cl>version: <span class=s2>"3"</span>
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>services:
|
|||
|
|
</span></span><span class=line><span class=cl> minecraft-server:
|
|||
|
|
</span></span><span class=line><span class=cl> build:
|
|||
|
|
</span></span><span class=line><span class=cl> context: .
|
|||
|
|
</span></span><span class=line><span class=cl> args:
|
|||
|
|
</span></span><span class=line><span class=cl> SERVER_MEM: <span class=si>${</span><span class=nv>SERVER_MEM</span><span class=si>}</span>
|
|||
|
|
</span></span><span class=line><span class=cl> SERVER_JAR: <span class=si>${</span><span class=nv>SERVER_JAR</span><span class=si>}</span>
|
|||
|
|
</span></span><span class=line><span class=cl> volumes:
|
|||
|
|
</span></span><span class=line><span class=cl> - .server-data:/server
|
|||
|
|
</span></span><span class=line><span class=cl> ports:
|
|||
|
|
</span></span><span class=line><span class=cl> - 25565:25565
|
|||
|
|
</span></span><span class=line><span class=cl> - 25575:25575
|
|||
|
|
</span></span><span class=line><span class=cl> container_name: <span class=si>${</span><span class=nv>CONTAINER_NAME</span><span class=si>}</span>
|
|||
|
|
</span></span><span class=line><span class=cl> restart: unless-stopped
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>volumes:
|
|||
|
|
</span></span><span class=line><span class=cl> server-data:
|
|||
|
|
</span></span></code></pre></div></li></ul></li><li><p><strong>Create the Dockerfile file</strong></p><ul><li>The Dockerfile builds the container. We take the 17-jre base
|
|||
|
|
image apply our variables change the working directory to
|
|||
|
|
/server and start the jar file, effectively starting the
|
|||
|
|
Minecraft server.</li><li><code>touch Dockerfile</code></li><li>Edit the file in a text editor, i.e. vim <code>vim Dockerfile</code><div class=highlight><pre tabindex=0 class=chroma><code class=language-bash data-lang=bash><span class=line><span class=cl>FROM eclipse-temurin:17-jre
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>ARG SERVER_MEM
|
|||
|
|
</span></span><span class=line><span class=cl>ARG SERVER_JAR
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>ENV <span class=nv>SERVER_MEM</span><span class=o>=</span><span class=si>${</span><span class=nv>SERVER_MEM</span><span class=si>}</span>
|
|||
|
|
</span></span><span class=line><span class=cl>ENV <span class=nv>SERVER_JAR</span><span class=o>=</span><span class=si>${</span><span class=nv>SERVER_JAR</span><span class=si>}</span>
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>WORKDIR /server
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>CMD <span class=nb>echo</span> <span class=s2>"Minecraft Server is starting\n"</span> <span class=o>&&</span> java -Xms128M -Xmx<span class=si>${</span><span class=nv>SERVER_MEM</span><span class=si>}</span>M -jar <span class=si>${</span><span class=nv>SERVER_JAR</span><span class=si>}</span> nogui
|
|||
|
|
</span></span></code></pre></div></li></ul></li></ol><h2 id=setup-the-server-files><strong>Setup the Server files</strong><a hidden class=anchor aria-hidden=true href=#setup-the-server-files>#</a></h2><p>We’re almost there, just a few steps left !!</p><p>The curious among you may have realised when trying to start the
|
|||
|
|
container that it fails with the error below:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-bash data-lang=bash><span class=line><span class=cl>Minecraft Server is starting
|
|||
|
|
</span></span><span class=line><span class=cl>
|
|||
|
|
</span></span><span class=line><span class=cl>Error: Unable to access jarfile server.jar
|
|||
|
|
</span></span></code></pre></div><p>This is because we have not downloaded the server jar file yet, that is
|
|||
|
|
our next step.</p><ol><li><strong>Navigate to one of the following sites:</strong><sup id=fnref:4><a href=#fn:4 class=footnote-ref role=doc-noteref>4</a></sup><ul><li><a href=https://www.minecraft.net/en-us/download/server target=_blank>Vanilla Minecraft Server</a>
|
|||
|
|
- instructions found here<sup id=fnref:5><a href=#fn:5 class=footnote-ref role=doc-noteref>5</a></sup></li><li><a href=https://fabricmc.net/use/server/ target=_blank>Fabric Mod loader server</a>
|
|||
|
|
- instructions found here <sup id=fnref:6><a href=#fn:6 class=footnote-ref role=doc-noteref>6</a></sup></li></ul></li><li><strong>Create a folder in the Minecraft-server folder called .server-data</strong><ul><li><code>mkdir .server-data</code></li><li><code>cd .server-data</code></li></ul></li><li><strong>Download the jar file - This will depend on the option above so read the instructions</strong></li><li><strong>Go back to the root minecraft-server folder</strong><ul><li><code>cd ..</code></li></ul></li><li><strong>Run the container</strong><ul><li><code>docker compose up</code> (use CTRL+C to exit)</li><li>Once the server unpacks all the files you will see this:<div class=highlight><pre tabindex=0 class=chroma><code class=language-bash data-lang=bash><span class=line><span class=cl>minecraft-server <span class=p>|</span> Starting net.minecraft.server.Main
|
|||
|
|
</span></span><span class=line><span class=cl>minecraft-server <span class=p>|</span> <span class=o>[</span>18:05:50<span class=o>]</span> <span class=o>[</span>ServerMain/INFO<span class=o>]</span>: You need to agree to the EULA in order to run the server. Go to eula.txt <span class=k>for</span> more info.
|
|||
|
|
</span></span><span class=line><span class=cl>minecraft-server exited with code <span class=m>0</span>
|
|||
|
|
</span></span></code></pre></div></li></ul></li><li><strong>Accept the EULA</strong><ul><li>Go into the .server-data folder<ol><li><code>cd .server-data</code></li></ol></li><li>Edit the file named eula.txt in a text editor i.e. vim <code>vim eula.txt</code><ol><li>Simply change <code>eula=false</code> to <code>eula=true</code></li></ol></li></ul></li><li><strong>While in the .server-data folder make any changes you want</strong><ul><li>Some files to note in here are<ul><li><strong>server.properties</strong> - properties like server name, game mode, world type etc…</li><li><strong>ops.json</strong> - list of server operators (easier to set ingame)</li><li><strong>whitelist.json</strong> - list of players allowed to join the server everyone else rejected access.</li></ul></li></ul></li><li><strong>Run the container</strong><ul><li><code>docker compose up -d</code> (the -d means detatched so we can run the server in the background)</li><li><code>docker logs minecraft-server --follow</code> Will show us the progress of the server startup (to exit out of this do CTRL+C)</li><li>If you see something like the following then you’re a winner 🥳<div class=highlight><pre tabindex=0 class=chroma><code class=language-bash data-lang=bash><span class=line><span class=cl><span class=o>[</span>18:17:01<span class=o>]</span> <span class=o>[</span>Server thread/INFO<span class=o>]</span>: Time elapsed: <span class=m>25529</span> ms
|
|||
|
|
</span></span><span class=line><span class=cl><span class=o>[</span>18:17:01<span class=o>]</span> <span class=o>[</span>Server thread/INFO<span class=o>]</span>: Done <span class=o>(</span>34.571s<span class=o>)</span>! For help, <span class=nb>type</span> <span class=s2>"help"</span>
|
|||
|
|
</span></span></code></pre></div></li></ul></li></ol><h2 id=conclusion>Conclusion<a hidden class=anchor aria-hidden=true href=#conclusion>#</a></h2><p>Well done you have successfully setup a Minecraft server, now go play !!
|
|||
|
|
There is a lot of cool stuff you can do with a Minecraft server for
|
|||
|
|
example installing mods or creating scripts to manage the server, this
|
|||
|
|
will be covered in the next post so keep an eye out for it !!</p><div class=footnotes role=doc-endnotes><hr><ol><li id=fn:1><p>Hosting your own dedicated server allows you to modify every aspect of the server as you see fit. I.E you can modify the server-properties, you can implement a whitelist not to mention being able to add any mods you want <a href=#fnref:1 class=footnote-backref role=doc-backlink>↩︎</a></p></li><li id=fn:2><p>Requirements Gathered from here <a href=https://minecraft.fandom.com/wiki/Server/Requirements/Dedicated#Unix_.28Linux.2C_BSD.2C_macOS.29 target=_blank>https://minecraft.fandom.com/wiki/Server/Requirements/Dedicated#Unix_.28Linux.2C_BSD.2C_macOS.29</a>
|
|||
|
|
 <a href=#fnref:2 class=footnote-backref role=doc-backlink>↩︎</a></p></li><li id=fn:3><p>Yaml is very picky 😞 when it comes to formatting so if you encounter any errors double check your formatting !! <a href=#fnref:3 class=footnote-backref role=doc-backlink>↩︎</a></p></li><li id=fn:4><p>I have left Forge out as it is a more involved process plus Fabric is better 😜 <a href=#fnref:4 class=footnote-backref role=doc-backlink>↩︎</a></p></li><li id=fn:5><p>Right click the green link that says something like minecraft_server.x.xx.x.jar and copy the link address</p><p>curl -o server.jar <link you copied here> <a href=#fnref:5 class=footnote-backref role=doc-backlink>↩︎</a></p></li><li id=fn:6><p>Select the Minecraft version, Fabric Loader Version and the Installer Version of your choice. I tend to go with the latest.</p><p>Copy the curl command under CLI download <a href=#fnref:6 class=footnote-backref role=doc-backlink>↩︎</a></p></li></ol></div></div><footer class=post-footer><ul class=post-tags><li><a href=https://blog.ahmza.com/tags/games/>Games</a></li><li><a href=https://blog.ahmza.com/tags/docker/>Docker</a></li><li><a href=https://blog.ahmza.com/tags/arm/>ARM</a></li></ul></footer></article></main><footer class=footer><span>© 2023 <a href=https://blog.ahmza.com>ahmza's ramblings</a></span>
|
|||
|
|
<span>Powered by
|
|||
|
|
<a href=https://gohugo.io/ rel="noopener noreferrer" target=_blank>Hugo</a> &
|
|||
|
|
<a href=https://github.com/adityatelange/hugo-PaperMod/ rel=noopener target=_blank>PaperMod</a></span></footer><a href=#top aria-label="go to top" title="Go to Top (Alt + G)" class=top-link id=top-link accesskey=g><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentcolor"><path d="M12 6H0l6-6z"/></svg></a><script src=https://storage.ko-fi.com/cdn/scripts/overlay-widget.js></script><script>kofiWidgetOverlay.draw("ahmza",{type:"floating-chat","floating-chat.donateButton.text":"Tip","floating-chat.donateButton.background-color":"rgb(145, 70, 255)","floating-chat.donateButton.text-color":"#fff"})</script><script>let menu=document.getElementById("menu");menu&&(menu.scrollLeft=localStorage.getItem("menu-scroll-position"),menu.onscroll=function(){localStorage.setItem("menu-scroll-position",menu.scrollLeft)}),document.querySelectorAll('a[href^="#"]').forEach(e=>{e.addEventListener("click",function(e){e.preventDefault();var t=this.getAttribute("href").substr(1);window.matchMedia("(prefers-reduced-motion: reduce)").matches?document.querySelector(`[id='${decodeURIComponent(t)}']`).scrollIntoView():document.querySelector(`[id='${decodeURIComponent(t)}']`).scrollIntoView({behavior:"smooth"}),t==="top"?history.replaceState(null,null," "):history.pushState(null,null,`#${t}`)})})</script><script>var mybutton=document.getElementById("top-link");window.onscroll=function(){document.body.scrollTop>800||document.documentElement.scrollTop>800?(mybutton.style.visibility="visible",mybutton.style.opacity="1"):(mybutton.style.visibility="hidden",mybutton.style.opacity="0")}</script><script>document.querySelectorAll("pre > code").forEach(e=>{const n=e.parentNode.parentNode,t=document.createElement("button");t.classList.add("copy-code"),t.innerHTML="copy";function s(){t.innerHTML="copied!",setTimeout(()=>{t.innerHTML="copy"},2e3)}t.addEventListener("click",t=>{if("clipboard"in navigator){navigator.clipboard.writeText(e.textContent),s();return}const n=document.createRange();n.selectNodeContents(e);const o=window.getSelection();o.removeAllRanges(),o.addRange(n);try{document.execCommand("copy"),s()}catch{}o.removeRange(n)}),n.classList.contains("highlight")?n.appendChild(t):n.parentNode.firstChild==n||(e.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName=="TABLE"?e.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(t):e.parentNode.appendChild(t))})</script></body></html>
|