[DOCKER] I tried to build Micra mackerel in 1 hour!


It all started when I was doing Minecraft with several friends. ** Friend "I want to do multiplayer even in Java version" ** Dove "No, I live in an apartment so I can open the port ..." At that time, the electric current runs on the pigeon ――――――――――! When I connected to a server-based notebook PC by SSH from the outside, I used something like ** ngrok ** to open the port in a pseudo manner ... If I applied it and did something with Docker, something like this You can do it! !! ?? That's why I was able to build Micra Saba by saying Eun Eun for about an hour, so I wrote an article as a personal memorandum & reference. I think that it should be useful for junior and senior high school students who can not connect to the line, or for those who suddenly want to build Micra mackerel on the go. I'm going to write it so that even people who don't know much about servers can build it, but I don't think people who don't know much about servers will read this article. If you are familiar with servers, this article may be a little confusing, so it is recommended to read it.

Ingredients (for 6 people)

--PC with Ubuntu ... 1 --Docker ... 1 animal --Ngrok ... 1 pick --nohup ... as you like

How to make


First is the ** server **. Since Docker is used, a server (PC) with ** Ubuntu ** (Linux OS) is desirable, but I think it's okay for some heroes to keep the power on while using WSL2 for a desktop with Win10. think. (In my opinion, Docker for Windows doesn't work well, so I recommend plain Ubuntu.) Docker Once the server is ready, let's install ** Docker ** next. In the first place, there may be some people who are Docker. Roughly speaking, it is a convenient tool that can be prepared by simply clicking on the troublesome environment construction such as the development environment and database. If you don't know, let's use it from now on. (I also want to write a Docker article) This If you read it, you can do it, but I'm writing an article, so I'll introduce it with a brief explanation.

First, update the existing package list to install the package!

$ sudo apt update

Install the packages required for Docker download!

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

Get the gpg key from the repository that contains Docker and save it!

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Allow Docker to be installed with apt!

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Updated package list!

$ sudo apt update

Confirm that the repository of the installation destination has changed ...

$ apt-cache policy docker-ce

Install Docker!

$ sudo apt install docker-ce

Now on the Ubuntu terminal

$ sudo docker --version

You can confirm that docker is running by hitting it. If you want to be able to use Docker without sudo, please refer to the above article.

Image of minecraft server

After successfully installing Docker, let's build Micra Saba! Docker is a great guy who can finish building the environment just by touching it, so Micra Saba only needs to build an existing template. itzg/minecraft-server Let's install and build the Docker image here (the environment construction is completed, it looks like the replication source data) with Docker.

$ sudo docker pull itzg/minecraft-server
$ sudo docker run -d -p 25565:25565 --name mc itzg/minecraft-server

Wait and it's done.

[Addition] Not ... If you execute the following log check, EULA will be told.

$ sudo docker logs mc

Please check the license agreement attached to the URL. Then, before going to the next, run fails and the container is stopped, so let's delete it once.

$ sudo docker rm `docker ps -alq`

Then, if you agree after confirming the above terms

$ sudo docker run -e EULA=TRUE -d -p 25565:25565 --name mc itzg/minecraft-server

Please run the. Wait here and you're done. The postscript is over.

Now, while I'm waiting, lightly explain the part of -p 25565: 25565. For example, if you access http://www.google.com with Google Chrome, it will look up the address (IP address) of the server that operates the Google site and go to that PC. An IP address is a list of numbers such as (By the way, if you write this list of numbers in the URL, you can jump to Google.) Since there is not only one service on this server, it is necessary to determine which service to receive. It is the port number that determines it. As an image, an office building containing multiple companies is a server, and each level has a company or an empty floor, and that level is like a port. Maybe. And in this article, the office building is on the PC with Ubuntu, and the hierarchy with the company is on the left 25565 of -p 25565: 25565. When you reach the 25565th floor of the server, there is a tunnel leading to the 25565th floor of Docker. When you reach the 25565th floor of Docker through the tunnel, it is an image that Micra's server is operated there. For example, I have explained the real thing in a mess, but please read it with a spirit ().

Did the Micra server stand? You can check the current situation with the following command.

$ sudo docker logs -f mc

ngrok Now that we have built a Micra server, all we have to do is invite customers to the Ubuntu server. I'd like to open the port, but I live in an apartment, and even if I can enter and exit the address (IP address) here, who visits my IP address, who's office building on what floor and in what room? I don't know. In other words, the port cannot be opened. ** ngrok ** for you! This is amazing. You can open the port in a simulated manner without pulling a personal line just by clicking! !! Even on the apartment line, you can directly access the server of my house by pulling the ngrok tunnel that connects to the outside! So download & install Install the packages required for download ...

$ sudo apt update
$ sudo apt install wget unzip

Download ngrok ...

$ wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip

Unzip! !!

$ unzip ngrok-stable-linux-amd64.zip

It's annoying and I don't think the pass is passing, so let's move it.

$ sudo mv ngrok /usr/bin/ngrok

You should be able to use it with this (maybe you needed a confirmation login after unverified) You can now access Micra's server by accessing server number 25565. I'll have you connect a tunnel to that

$ ngrok tcp 25565

When you hit, a URL that can be accessed from the outside will be issued. It seems that a URL like tcp: //X.tcp.ngrok.io: YYYYY (X, YYYYY are numbers) will be issued. With this, your friends can also invite you to Java Micra Multi! Yay! !! !! Open Micra in Java version and select "Multiplayer"-> "Add Server" to freely change the server name and set the server address to "X.tcp.ngrok.io: YYYYY" (X, YYYYY are numbers) displayed earlier. If you participate, everyone can play! !! nohup You don't have to do this separately, but if you want the server to run other processes, or if you want to disconnect the server's SSH connection, you'll have to stop ngrok. Therefore, it is necessary to have it turned behind the scenes. That's where ** nohup ** comes in handy. When opening a port with ngrok

$ nohup ngrok tcp 25565&

Just hit and the terminal will be returned. But with this, the URL cannot be confirmed, so

$ curl localhost:4040/api/tunnels

You can check information such as the status of ngrok by tapping. There is an item "public_url" at the top, and the URL is written there. You have now built Micra's mackerel completely in the background! !! Congrats! !! !! !!

Digression (You can close the browser at this point)

It was a Micra server that was finally built, but in the end, friends were crazy about the data that had been advanced in the integrated version, and no one came to Saba.

(´ ・ ω ・ `)

As an aside, I heard that Celeron has low power and is good for servers, so I overwrote Windows on my laptop with Ubuntu Server to make it a server. However, I am considering a rental server because it is not good to use a notebook PC as a server because it burns. (If you rent a rental server, you don't need this article) Well, I'm sure there will be demand for high school students when they build Saba.

Recommended Posts

I tried to build Micra mackerel in 1 hour!
I tried to build AdoptOpenjdk 11 on CentOS 7
I tried to build Ruby 3.0.0 from source
I tried to implement polymorphic related in Nogizaka.
I tried to organize the session in Rails
I tried to implement deep learning in Java
I tried to build a Firebase application development environment with Docker in 2020
I tried to build AdoptOpenJDK 8 (Addition: Amazon Corretto 8)
I tried to output multiplication table in Java
I tried to develop an application in 2 languages
I tried to create Alexa skill in Java
I tried to organize the cases used in programming
I tried to implement Firebase push notification in Java
# 2 [Note] I tried to calculate multiplication tables in Java.
I tried to create a Clova skill in Java
I tried to make a login function in Java
I tried to implement the Euclidean algorithm in Java
~ I tried to learn functional programming in Java now ~
I tried to find out what changed in Java 9
I tried to build an environment using Docker (beginner)
I tried to verify yum-cron
I tried metaprogramming in Java
I tried to make an application in 3 months from inexperienced
I tried to build the environment little by little using docker
I tried to convert a string to a LocalDate type in Java
I tried to build the environment of WSL2 + Docker + VSCode
I tried using Dapr in Java to facilitate microservice development
I tried to implement a buggy web application in Kotlin
I tried to make a client of RESAS-API in Java
I tried to summarize object orientation in my own way.
I tried to chew C # (indexer)
I tried to summarize iOS 14 support
I tried to interact with Java
I tried to explain the method
I tried putting Domino11 in CentOS7
I tried using JWT in Java
I tried to summarize Java learning (1)
I tried to understand nil guard
I tried to summarize Java 8 now
I tried to chew C # (polymorphism: polymorphism)
I tried to explain Active Hash
I tried to summarize the words that I often see in docker-compose.yml
I tried to create a simple map app in Android Studio
I tried to implement Ajax processing of like function in Rails
I tried to illuminate the Christmas tree in a life game
I tried to sort the data in descending order, ascending order / Rails
I tried to build the environment of PlantUML Server with Docker
I tried to write code like a type declaration in Ruby
I tried setting Java beginners to use shortcut keys in eclipse
I tried to build an http2 development environment with Eclipse + Tomcat
I tried to build a simple application using Dockder + Rails Scaffold
I tried to make Numeron which is not good in Ruby
I tried to build a laravel operating environment while remembering Docker
I tried to make a parent class of a value object in Ruby
I tried using Elasticsearch API in Java
I tried a calendar problem in Ruby
I tried to summarize the methods used
I tried to introduce CircleCI 2.0 to Rails app
I tried migrating Processing to VS Code
I tried to summarize Java lambda expressions
I tried to get started with WebAssembly