How to deploy with `docker run`

I want to deploy GitHub - itzg/docker-minecraft-server: Docker image that provides a Minecraft Server that will automatically download selected version at startup using Fly.io, but I am having trouble finding how to deploy an application using only a docker run command.

If anyone is wondering, here is the docker run command:

docker run -d -it -p 25565:25565 -e EULA=TRUE itzg/minecraft-server
1 Like

Yep, I agree it would be good if some docs were added for this since other people have asked e.g

In theory you could deploy a public image using the fly CLI, like: fly deploy --remote-only -i example/image. But that would need adapting to add params.

1 Like

Funny enough that Minecraft image was one I also played with locally and totally would have tried out on fly if there was an easy way to convert the run command :smiley:

In many cases (like this one) you can craft or find a Dockerfile via docker inspect or docker history.

For the docker run command listed above, you’d just have to keep in mind that docker run -p 25655:25655 corresponds to internal_port:port in your fly.toml. Our tcp-echo and udp-echo example apps might come in handy here, too.

I’ve managed to get it running, although on the trial plan I get this message:

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 357892096, 0) failed; error='Not enough space' (errno=12)

This is my fly.toml:

app = "mc"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]
  EULA="TRUE"

[experimental]
  allowed_public_ports = [25565, 25575] # 25565 is the default port for Minecraft, and 25575 is the port for RCON
  auto_rollback = true

[mounts]
source="mc"
destination="/data"

[[services]]
  http_checks = []
  internal_port = 25565
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

And here is my fly deploy command:

fly deploy --remote-only -i itzg/minecraft-server

Unfortunately, I am no position financially currently to pay for resources so someone else will have to test if it truly works.

Yup, I had to scale it up to get the app to deploy successfully. I gave it dedicated-cpu-2x and --memory 4096. I can’t speak to its actual performance, since I don’t have a minecraft client myself, but it deployed surprisingly quickly when compared to a local build.

I don’t think I ended up deploying any http/tls handlers. Instead, my allowed_public_ports field an my services.ports section just had my app listening on 25565.

I only configured the health check for 25565 as a basic PoC since I’ve never actually played minecraft :sweat_smile: but I could see it on its public ip address!

1 Like

Docs page :eyes:?

1 Like

That’s a good idea! I’m pretty sure a few other people on the team have tried their hand at minecrafting in the past, so it’s definitely worth a shot :slightly_smiling_face:

1 Like

Also if you need I can test out the server for you.

1 Like

I used a local Dockerfile to deploy pretty similar to what @cursecode shows above, the advantage with the Dockerfile being that you can configure the server easier than with command line args, also it seems to work pretty well with mods too.
fly.toml:
Some of the udp ports may not be needed but I’m not a minecraft or networking expert

# fly.toml file generated for fly-minecraft on 2022-08-05T17:44:05-04:00

app = "fly-minecraft"
kill_signal = "SIGINT"
kill_timeout = 60
processes = []

[mounts]
source="minecraft_data"
destination="/data"

[env]

[experimental]
  allowed_public_ports = [19132, 19133, 25565]
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 25565
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    port = 25565

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[services]]
  internal_port = 19132
  protocol = "udp"

  [[services.ports]]
    port = 19132

[[services]]
  internal_port = 19133
  protocol = "udp"

  [[services.ports]]
    port = 19133

[[services]]
  internal_port = 25565
  protocol = "udp"

  [[services.ports]]
    port = 25565

Dockerfile:

FROM itzg/minecraft-server:java8
COPY --chown=1000 ROTN_311a_Server.zip /
ENV EULA=true
ENV TYPE=CURSEFORGE
ENV CF_SERVER_MOD=/ROTN_311a_Server.zip
ENV CF_BASE_DIR=/data
ENV MEMORY=6G
ENV ENABLE_RCON=true
ENV RCON_PASSWORD={rcon-password}
ENV RCON_CMDS_LAST_DISCONNECT="/save-all"
ENV RCON_PORT=25575
ENV ROLLING_LOGS=true

Some mods may overwrite some of the settings so you may have to end up changing the server.properties file to have the values or set OVERRIDE_SERVER_PROPERTIES=true . But that seems to overwrite all values in the server.properties file rather than just the specified ones.