1

Forgive the vague question title, I'm a complete beginner and I lack the terminology to pose my question more specifically.

I've been developing a simple application that consists of a game server (using socket.io, so WebSockets) and a game client, which is just an HTTP server. I've finished developing locally and would now like to host it on the servers of my student organisation; seeing as that machine already has Docker installed I figured that would be the easiest solution.

Concretely, in local development I've set the WebSockets server to use port 3141 and the HTTP server to use port 5173. I tried my hand at using docker compose and came up with the following configuration:

services:
  server:
    build: .
    ports:
      - 3141
  frontend:
    build: ./kwispel-client
    ports:
      - 5173

Using docker inspect kwispel-server-server-1 I can then manually figure out the IP address of the HTTP server and connect to it. However, container naming resolution doesn't work; I need that for

  • telling the client side of socket.io where to connect to, and passing in http://server:3141 doesn't work;
  • telling the server side of socket.io which CORS headers to allow, and passing in http://frontend:5173 doesn't work Locally the project works fine using localhost instead of server or frontend.

If I try defining a shared network, like such:

services:
  server:
    build: .
    ports:
      - 3141
    networks:
      kwispel-server_gedeeldNetwerk:
        ipv4_address: 172.16.238.10  
  frontend:
    build: ./kwispel-client
    ports:
      - 5173
    networks:
      kwispel-server_gedeeldNetwerk:
        ipv4_address: 172.16.238.20
networks:
  kwispel-server_gedeeldNetwerk:
    driver: bridge
    ipam:
      config:
        - subnet: "172.16.238.0/24"

so that I can have fixed IP addresses, I can't even connect to the HTTP server on that address.

Am I missing something obvious? Do I need to pass an extra flag to docker-compose up to expose the ports I need? I'm at a complete loss. Any pointers in the right direction are much appreciated.

1 Answer 1

1

Looks like you need a Dockerfile to build your image. What I like to do is build the image, first, then reference that image in docker-compose.yml such that I am only using docker-compose for running the containers.

Here is a good tutorial with an example of a Dockerfile that can help: https://dockerize.io/guides/node-socket-giude

Also, have a look at existing Docker images that have socket.io support: https://hub.docker.com/search?q=socket.io

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.