itzg/docker-mc-proxy

Couldn't connect to default server using localhost or container DNS

bastien-snk opened this issue · 13 comments

When I want to connect to my default server using the BungeeCord, it disconnects me and returns the error: "Could not connect to a default or fallback server, please try again later: Server not reachable (timeout). Offline? Incorrectly configured address/port/firewall?" However, my default server is present at the address: localhost:25565.
I tried to connect both of them with different addresses such as:

  • localhost
  • 127.0.0.1
  • 0.0.0.0
  • test-lobby (container name DNS resolved by Docker)
  • My public IP

I also tried to modify the server-ip field in server.properties to see if it was not that, I tried:

  • 0.0.0.0
  • 127.0.0.1

Here is the list of my containers:
image

Proxy logs:
_test-proxy_logs.txt

Lobby logs:
_test-lobby_logs.txt

itzg commented

Please provide the container configs you are using. Better yet, start back as the baseline examples

https://github.com/itzg/docker-bungeecord/tree/master/docs

and iterate from there.

I changed my BungeeCord config.yml with the one provided in the link you sent, but it doesn't change anything
This is the JSON which i send to DockerEngineAPI (v1.41 / latest) to create the containers:

Edit: I tried with the docker-compose you sent but still had the same issue

Proxy

{
    "Image":"itzg/bungeecord",
    "AutoRemove":true,
    "Env":[
        "TYPE\u003dBUNGEECORD",
        "REPLACE_ENV_VARIABLES\u003dTRUE"
    ],
    "HostConfig":{
        "PortBindings":{
            "25577/tcp":[
                {
                    "HostIp":"0.0.0.0",
                    "HostPort":"25577"
                }
            ]
        },
        "Mounts":[
            {
                "Target":"/config",
                "Source":"C:\\Users\\basti\\Documents\\GitHub\\TestDocker\\src\\main\\resources\\modules\\proxy\\config",
                "Type":"bind",
                "ReadOnly":false
            },
            {
                "Target":"/plugins",
                "Source":"C:\\Users\\basti\\Documents\\GitHub\\TestDocker\\src\\main\\resources\\modules\\proxy\\plugins",
                "Type":"bind",
                "ReadOnly":false
            }
        ],
        "Binds":[
            
        ]
    },
    "Config":{
        "AttachStdin":false,
        "AttachStdout":false,
        "AttachStderr":false
    },
    "Tty":true,
    "OpenStdin":true,
    "Volumes":{
        
    },
    "Args":[
        
    ]
}

Lobby

{
    "Image":"itzg/minecraft-server:java8",
    "AutoRemove":true,
    "Domainname":"test-lobby",
    "Env":[
        "TYPE\u003dCUSTOM",
        "CUSTOM_SERVER\u003d/data/server.jar",
        "EULA\u003dTRUE",
        "REPLACE_ENV_VARIABLES\u003dTRUE",
        "SERVER_PORT\u003d25565",
        "SERVER_NAME\u003dtest-lobby"
    ],
    "HostConfig":{
        "PortBindings":{
            "25565/tcp":[
                {
                    "HostIp":"0.0.0.0",
                    "HostPort":"25565"
                }
            ]
        },
        "Mounts":[
            {
                "Target":"/data",
                "Source":"C:\\Users\\basti\\Documents\\GitHub\\TestDocker\\src\\main\\resources\\modules\\lobby\\data",
                "Type":"bind",
                "ReadOnly":false
            }
        ],
        "Binds":[
            
        ]
    },
    "Config":{
        "AttachStdin":false,
        "AttachStdout":false,
        "AttachStderr":false
    },
    "Tty":true,
    "OpenStdin":true,
    "Volumes":{
        
    },
    "Args":[
        
    ]
}
itzg commented

I meant the compose file mainly. You have the port bindings flipped for one thing. I would suggest you start with getting it to work with compose and then port that over to using the API directly.

I tried with the compose file, but nothing changes. Do you think my port bindings are reversed? If it's just that problem, I'll try again with a front-end compose to see and then with the API.

Update: I tried changing and inverting the ports on my host to see if they were inverted and they don't seem to be.

itzg commented

If this compose setup exactly as provided is not working for you then you need to debug your docker installation, networking, because it works fine for me:

https://github.com/itzg/docker-bungeecord/blob/master/docs/docker-compose.yml

itzg commented

...in case you don't know what I mean by port bindings flipped:

        "PortBindings":{
            "25577/tcp":[
                {
                    "HostIp":"0.0.0.0",
                    "HostPort":"25577"
                }
            ]
        },

should be

        "PortBindings":{
            "25577/tcp":[
                {
                    "HostIp":"0.0.0.0",
                    "HostPort":"25565"
                }
            ]
        },

and you should not have a host port binding for the minecraft container.

Okay so, I did everything you asked, here is the updated configuration for the ports:

image

This gives the following for the proxy container:

"PortBindings": {
                "25577/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "25565"
                    }
                ]
            },

Here is the configuration of the "mc" server in bungeecord.yml:

servers:
  lobby:
    address: test-lobby:25565
    restricted: false
    motd: ""

But the issue is still there, it didn't work either with the docker-compose you sent me. I am on WSL with Docker Desktop but it doesn't seem to be a problem but we are never 100% sure

Update: I made it work with the docker-compose

itzg commented

My test just now was on WSL 2. I can't help any further since I can't recreate the issue and your screenshot is not even of the the example I asked you to try.

I would recommend reading up on https://docs.docker.com/network/

Update: I managed to get it to work with its own docker compose, but when I do it with the api, it doesn't work. However the parameters are exactly the same, I can provide the JSON data if needed.

Here is the docker-compose used which works:

version: '3.9'

services:
  proxy:
    image: itzg/bungeecord
    container_name: test-proxy
    stdin_open: true
    tty: true
    ports:
      - "25577:25577"
    volumes:
      - C:\Users\basti\Documents\GitHub\TestDocker\a remove\lyramc\proxy\config:/config
      - C:\Users\basti\Documents\GitHub\TestDocker\a remove\lyramc\proxy\plugins:/plugins
    environment:
      TYPE: CUSTOM
      BUNGEE_JAR_FILE: "/config/server.jar"

      INIT_MEMORY: 512m
      MAX_MEMORY: 512m

      REPLACE_ENV_VARIABLES: "TRUE"
      ENV_VARIABLE_PREFIX: ""
    restart: "no"
    networks:
      - "backend"
  lobby:
    image: itzg/minecraft-server:java8
    restart: "no"
    tty: true
    stdin_open: true
    container_name: test-lobby
    ports:
      - "25565:25565"
    volumes:
      - C:\Users\basti\Documents\GitHub\TestDocker\a remove\lyramc\lobby:/data
    environment:
      TYPE: "CUSTOM"
      CUSTOM_SERVER: /data/server.jar
      EULA: "TRUE"
      REPLACE_ENV_VARIABLES: "TRUE"
      SERVER_PORT: 25565
      SERVER_NAME: test-lobby
    networks:
      - "backend"

networks:
  backend:
    name: backend
    driver: bridge
    #internal: true # Disable internet
itzg commented

There are some particular things compose does to make sure the servers are registered with the appropriate hostnames in the network it creates. So you should compare very closely with both the containers and the network when translating to the API call.

The problem was not with the networks, but with the aliases of the containers so that they could not resolve the domain name. I got it to work by adding the following aliases to each container:

  • Container name
  • Container ID