Search code examples
dockersocket.iopython-socketio

Docker SocketIO not found (Python)


When running my Python-SocketIO app normally, the SocketIO connection to the frontend works fine. In a docker container, it can't be connected to.

Output from Docker container:

======== Running on http://0.0.0.0:8080 ========

(Press CTRL+C to quit)

A similar problem was brought up for the standard SocketIO but Python-SocketIO doesn't mention a config.json file, therefore I didn't include one to any capacity. I also don't believe it matters because the program's output already depicts 0.0.0.0:8080 as opposed to 127.0.0.1:8080

My run configuration(s): -> Have tried all

docker run --rm -d <CONTAINER_ID>
docker run --rm -d --network host <CONTAINER_ID>
docker run --rm -d --network host <CONTAINER_ID> -p 0.0.0.0:8080/tcp

8/19/20 NOTE: Connection to docker container is made via the Client API.


Solution

  • I assume the <CONTAINER_ID> in your run commands is a custom image tag? Containers and images are different things.

    The problem looks to be that you aren't using the correct form for the -p/--publish argument to the run command. In the simplest form, you would use {host-port}:{container-port}, e.g. 8080:8080. You can optionally be explicit that the port should be on all interfaces with 0.0.0.0:8080:8080, or restrict to host loopback with 127.0.0.1:8080:8080. Add on the /tcp to the end to restrict to only TCP packets. You can make the container port 8080 exposed on a random dynamic port with 0.0.0.0::8080 (note the extra colon!), or instead use -P/--publish-all to do that with all exposed ports on the container.

    It sounds like you want to use something like this to mimic running the application outside of a container:

    docker run --rm -d -p 0.0.0.0:8080:8080 <IMAGE_TAG>

    The networking of containers can get pretty involved, the docs on links is a decent primer on the possible configurations.