# DigitalOcean Docker Minecraft Server Guide ###### tags: `unix` `minecraft` 1. create droplet (attach to existing volume) 2. follow config instructions in volume ssh into droplet ```bash= mkdir -p /mnt/mc_volume && mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_Volume_mc-volume /mnt/mc_volume && echo '/dev/disk/by-id/scsi-0DO_Volume_mc-volume /mnt/mc_volume ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab && cd /mnt/mc_volume && ls -la ``` 4. start mc server ```bash= docker run -d -it \ -p 25565:25565 \ -e EULA=TRUE -e MEMORY=7000M -e DEBUG_MEMORY=true -e VERSION=1.15.2 \ -e TYPE=FORGE -e FORGE_INSTALLER=forge-1.15.2-31.2.45-installer.jar \ -e ENABLE_AUTOPAUSE=TRUE -e AUTOPAUSE_TIMEOUT_EST=1200 \ -e JVM_XX_OPTS='-Xms7200M -Xmx7200M -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50' \ -e JVM_DD_OPTS=fml.queryResult:confirm \ -v /mnt/mc_volume:/data \ --user root --restart on-failure \ --name mc itzg/minecraft-server:latest ``` to start the minecraft server again after you've done it the first time just do ```docker start mc``` #### **P.S.**: If the server generates and the world is different, copy the serverworld folder into /mc_volume and replace everything inside the generated world folder with stuff from the serverworld folder. 5. shutdown ssh thing ```shutdown now``` 6. destroy droplet you made in cloud.digitalocean.com ## Rebooting SSH ```bash= sudo reboot ``` ## Volume showing less space than available (887 MB instead of 4GB) fix ```bash= e2fsck -f /dev/sda ``` (add sudo to the front if it doesn't work) ## Guide to copying files If you get a permission error when attempting to copy files with ssh and username:ipaddress, run this command on the folder you need permissions for (in this case it's mc_volume) `sudo chown -R username:username /mnt/mc_volume` 1. Go to the folder on your computer you want to copy stuff from 2. copy your files like this: copying a single file ```scp file.txt root@165.22.103.122:/mnt/mc_volume``` copying an entire directory (requires recursive -r) ```scp -r directoryname root@128.199.190.249:/mnt/mc_volume``` copying everything inside a directory ```scp directoryname/* root@128.199.190.249:/mnt/mc_volume``` ƒ (the colon is required by the :/mnt because reasons) copying a file from ssh volume to local filesystem (be in the terminal in your filesystem) (in root directory) ```bash= cd Documents/mc ``` ```bash= scp root@128.199.190.249:/mnt/mc_volume/world/level.dat server/ ``` copying a folder from ssh volume to local filesystem (in root directory) ```cd Documents/mc``` ```scp -r root@128.199.190.249:/mnt/mc_volume/world server/``` #### How to rename a file/directory file ```mv oldname newname``` folder ```mv -r olddirname newdirname``` ## Linking a server to a domain name 1. login to Namecheap and go to Advanced DNS in your domain settings 2. create a new SRV record with the service set to `_minecraft` the protocol set to `_tcp` priority set to `0` weight set to `5` port set to `25565` target set to your domain `mc.myserver.com` TTL can be as fast as you want 3. create a new A Record with the host being the preferred subdomain such as mc 4. set the value to the server's IP Address 5. the server should update automatically you don't need to restart it ## Port forwarding (for synology router) 1. go to Network Center 2. go to Local Network > DHCP Clients 3. find the computer the server is running on 4. select it and add to address reservation 5. go to Port Forwarding 6. press Create and give it a name like 'minecraft server' 7. in Private IP Address select the computer's IP Address from a list 8. in Public and Private Ports type 25565 9. Protocol should be set to TCP/UDP, then create ## Adding Dynamic DNS (DDNS) to a server domain name [Namecheap's DDNS Info Page](https://www.namecheap.com/support/knowledgebase/article.aspx/36/11/how-do-i-start-using-dynamic-dns/) 1. open up namecheap's Advanced DNS (make sure your domain nameserver is not set to Custom DNS). 3. Change the existing A Record to a placeholder value like 127.0.0.1 (or just delete it) 4. Scroll down and enable Dynamic DNS 5. add a new A+ Dynamic DNS Record and give it the same host as the previous A Record (in my case the mc subdomain) (note: don't have duplicate IP Addresses for your A Records or you can't delete them and have to contact support to do it) 7. set the IP Address to the placeholder value of 127.0.0.1 8. SSH into the server connected to your router, go to `/mnt/` and create a new folder for the ddclient 9. inside the new folder install ddclient as a docker container [here](https://hub.docker.com/r/linuxserver/ddclient) 10. or you can run the docker-compose.yml file below with `docker-compose up -d` ``` version: "2.1" services: ddclient: image: ghcr.io/linuxserver/ddclient container_name: ddclient environment: - PUID=1000 - PGID=1000 - TZ=Continent/City volumes: - /mnt/ddns-thing:/config restart: unless-stopped ``` 11. After you run it for the first time a new ddclient.conf file will appear 12. do `docker-compose down` to shut down the container 13. `nano` into it (if this does not happen, do `docker rmi ghcr.io/linuxserver/ddclient ; docker rm (containerid)` (do `docker ps -a` to view existing containers) to clear out stuff then try running docker-compose again 14. in the ddclient.conf file scroll down to Namecheap and replace the stuff below ``` ## ## Namecheap (namecheap.com) ## ``` and above loopia with ``` use=web, web=https://dynamicdns.park-your-domain.com/getip \ protocol=namecheap, \ server=dynamicdns.park-your-domain.com, \ login=serverurl.com, \ password=thenamecheapDDNSpassword \ subdomain ``` **make sure it is uncommented!** (replace subdomain with @ if not using subdomain) 15. close and save, then re-run `docker-compose up -d` 16. check logs with `docker logs ddclient`, it should say ``` [cont-init.d] 10-adduser: exited 0. [cont-init.d] 30-config: executing... [cont-init.d] 30-config: exited 0. [cont-init.d] 99-custom-files: executing... [custom-init] no custom files found exiting... [cont-init.d] 99-custom-files: exited 0. [cont-init.d] done. [services.d] starting services Setting up watches. Watches established. [services.d] done. SUCCESS: updating mc: good: IP address set to [Port forwarded ip address] ``` ## Troubleshooting Errors fixes for various errors that may arise. ### Server Launching With Old Parameters delete the .forge-installed file that may be leftover in the mc_volume folder. ### Biomes O Plenty World Type Fix 1. Copy level.dat and level.dat_old from the world folder (for how to copy, read copy file from ssh volume above) 2. Open [WebNBT](https://irath96.github.io/webNBT/) on a browser 3. Drop level.dat onto the site 4. Go to level.dat > Data 5. Change levelgenerator from default to ```biomesoplenty``` (1.15) (do this for both level.dat and level.dat_old) 6. Save and download files, copy them to the world folder (rename the files to something else first) 7. Rename the existing level.dat & level.dat_old files to something like "old_level.dat" 8. Rename the newly downloaded .dat files to level.dat & level.dat_old 9. Open server.properties ```nano server.properties``` 10. Change level-type to ```level-type=biomesoplenty``` 11. Restart the server and test with Nature Compass