4. Configure your ports
When spinning up containers on a machine, our orchestrator has to decide upfront which networking modes it puts a container in. This affects how external clients (your players) will connect to the game server application running inside the container.
The Docker Engine has two built-in networking modes. As Gameye is a layer on top of the Docker Engine, our orchestrator can use them both and decide which is best according to your needs.
Learn more about bridge networking. For a more in-depth description of bridge networking, check Docker’s website.
Bridge networking lets multiple containers bind to any port without clogging up the networking stack of the host machine. For example, you have 10 different nginx containers and they should all bind to port 8080.
How does traffic flow to these nginx instances?
The bridge network opens up an ephemeral port and links it to port 8080 of a specific container. As Docker keeps track of these networks and containers, it can easily forward all traffic.
When we create a new container, our orchestrator automatically allocates an ephemeral port (between 32768 and 60299). As the orchestrator knows all the containers (and where they’re running), it searches for an available port in ascending order.
If you use bridge networking, your Dockerfile from step three will stay the same.
Learn more about host networking. For a more in-depth description of host networking, check Docker’s website.
Host networking is where you keep reusing the networking stack of the host machine. When a container needs to reserve a specific port (like 8080), it’ll block any other container from using that port. That means only one container on the whole machine uses port 8080.
That can obviously clog up the ports. So to prevent that, our orchestrator needs to allocate an ephemeral port to use instead (between 32768 and 60299). As the orchestrator knows all the containers (and where they’re running), it searches for an available port in ascending order.
Once we’ve chosen the port, we add it as an environment variable (like GAMEYE_PORT_TCP_8080). The container then has access to the port. It can then bind or publish the port as metadata to matchmakers, clients or other services.
If you want to use host networking, there are a few tweaks you need to make to your Dockerfile from step three and your ENTRYPOINT. You can use the following code blocks to help you make those changes.