Host my Own Minecraft Server on AWS EC2 using Docker
Tags: aws, minecraft, docker, todayilearned
Published: 2022-06-11 03:29:41

Hello, everyone! How are you today? I'm going to explain about setup Minecraft Server on AWS EC2. We will use Docker to run the Minecraft Server to minimize the setup of our AWS EC2. Let's go!

## Prepare SSH Client

* For Windows, you may use [putty](https://www.putty.org/) or another SSH client.
* For Ubuntu, you can check [this article](https://www.cyberciti.biz/faq/how-to-install-ssh-on-ubuntu-linux-using-apt-get/) on how to install it

## Prepare AWS EC2

1. Visit EC2 page. Make sure you are visiting the correct region.

    ![EC2 Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8166vdd6u8locc5lheli.png)

2. Click on Instances. After that, click Launch Instances.

    ![Launch Instances](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ms2t4m453jeot00pxeay.png)

3. Fill in the EC2 name. After that, please make sure the number of instances is 1. Finally, choose Ubuntu as the OS. Note: You may choose another OS. But, you will need to find how to set up Docker for your selected OS.

    ![Fill Details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8o9dgfn7p4hb3zbrtp5p.png)

4. Select instance type. I'm using `t3.small` since I will not have many users on my own server. Feel free to choose another instance type. But, I will recommend using `t3.small` as a minimum specification.

    ![Choose Instance Type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40ecmpwk10dmbbh2hdvl.png)

5. Choose your key pair. If you don't have it yet, you may create new `key pair` using `Create new key pair` link. You will need this to SSH into your server.

6. Now, we will set up the network. Please click Edit on the Network Setting section. After that, choose the subnet as you wish. I select `ap-southeast-3c`. I disable Auto-assign public IP since I will use Elastic IP.

    ![Subnet and auto-assign public IP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h8zj0hjrtx01kn6spqr.png)

7. We will create a new security group. Make sure you've selected `Create security group`. Update the Security group name with an appropriate name, for example, `minecraft-server-security-group`, etc. Click `Add security group rule`, and fill in the Port range for `Security group rule 2` with 25565. Port 25565 will be used to host the Minecraft server. Click on the source, and make sure you choose `0.0.0.0/0`.

    ![Security Group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtf5k10zuglli5ziyscx.png)
 
8. Please fill in your desired volume size in Configure volume section. I use 25 GiB.

    ![Volume](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k265edf60v8vcmx10t3.png)

9. Click `Launch instance` in the summary section.

    ![Launch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4x5j2oxwx9hvx6a7dx2.png)

### Setup the Elastic IP

1. Go to the VPC page, and select Elastic IPs. After that click the `Allocate Elastic IP address` button.

    ![Allocate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7idhnh3rb1tpc5doemc.png)

2. I use default options, and click `Allocate`.

    ![Allocate fields](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mkbsh0myksxez8finvv.png)

3. You will get the notification message, and click the `Associate this Elastic IP address` button.

    ![Notification](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gm502mf5atomyebtgaas.png)

4. Select the instance you've created before. After that, click Associate button.

    ![Assign](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m7laz5vchwpvpc384qij.png)

### SSH to our EC2 using Public IP

1. Make sure you can SSH to our previous EC2.

    ![SSH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ts9szpx2ayr0gfrmeq05.png)
 
2. Update our package reference using `sudo apt update`.

    ![apt update](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lzleppkxcsysdjfh6flo.png)

3. Install docker. You might want to read [this article](https://docs.docker.com/engine/install/ubuntu/) on how to install the docker. Note: Since I want to use docker without `sudo` for my `ubuntu` user, you might want to read [this](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user). Make sure you are re-login after setup that.
  
4. Check your docker installation. I use `docker ps`.

    ![ps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1k1x5lzq2dg18eb7nz06.png)

## Run Minecraft Server

1. We will use [this](https://hub.docker.com/r/itzg/minecraft-server) docker image.

2. We will use `docker compose` too. So, prepare the `docker-compose.yml` and host the `yml` on `minecraft` directory. I use this configuration. Note: If you want to know more the environment values to customize your server, please visit [this](https://github.com/itzg/docker-minecraft-server).

    ```yml
    version: "3"

    services:
      mc:
        image: itzg/minecraft-server:java17-alpine
        ports:
          - 25565:25565
        environment:
          EULA: "TRUE"
        tty: true
        stdin_open: true
        restart: unless-stopped
        volumes:
         # attach a directory relative to the directory containing this compose file
          - ./minecraft-data:/data
    ```

3. Start our server! `docker compose up -d`.

4. To monitor the process, you may use `docker compose logs -f`. To quit the logs monitor, use `CTRL+C`.

    ![logs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9ycoqjzb7324xtbxrj6.png)
 

## Let's Play!

1. Please use your Minecraft Client application.
 
2. Input your EC2 IP address and port into your Minecraft Client application. Enjoy your server!

    ![server](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/koaijhgaa8u189jjrcha.png)

## Additional

* If you need to auto-start and auto-stop your EC2 instance. Please check [this article](https://aws.amazon.com/premiumsupport/knowledge-center/start-stop-lambda-eventbridge/).
* If you want to explore another alternative. I think you may try another Amazon Machine Image (AMI).

![AMI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9w2l71laza6w1lj1vy67.png)

## Thank you

Thanks for reading! If you have feedback, feel free to comment on this post.

![Thanks](https://media.giphy.com/media/Pnh0Lou03fv92J4puZ/giphy.gif)