Flask Docker container SocketIO Issues Flask Docker container SocketIO Issues flask flask

Flask Docker container SocketIO Issues


TL;DR - you're using incompatible socketIO versions between client and server. Check the table below and make sure you're using the appropriate python & javascript versions.

Like the container logs say, you're using incompatible versions of SocketIO between client and server. The SocketIO & EngineIO protocols have been through several revisions, and they're not all backward compatible, so you have to make sure you're using appropriate implementations of the protocol on the client and server side that can talk to one another.

I suspect that the reason it's working when you run your app locally but not in your Docker container is because the dependencies in your container's requirements.txt are referencing older, incompatible versions of the python implementation. Based on what you described, it seems like the locally installed python implementation of socketIO is a newer version, and therefore compatible with the newer JS version on client-side, and has no trouble connecting (or it could be vice-versa....older client, newer server).

If you're using the native javascript Socket.IO version 3.0+ on the client side (which implements the SocketIO Protocol v5 and EngineIO Protocol v4), then you need to make sure you're using the appropriate versions of the Python implementations on the server side. You didn't specify, but I assume you're using Flask-SocketIO, which itself is a wrapper around python-socketio, the actual Python implementation of the SocketIO protocol.

Check what version of SocketIO client you are using in your Javascript. Then check your requirements.txt and make sure the python-socketio version is compatible, per the below table (source):

JS SocketIO VersionSocketIO ProtocolEngineIO Protocolpython-socketio
0.9.x1, 21, 2Not supported
1.x and 2.x3, 434.x
3.x545.x

You're most likely using the JS version 3.x with the 4.x version on the python side (which are NOT compatible). Make sure that you are using Flask-SocketIO v5.x, python-socketio v5.x, and python-engineio v4.x, and that your JS client is 3.x. That should fix your problem.

If this is working properly in your local environment, then you could simply runpip freeze > requirements.txt and use that for your docker build. This requirements.txt file would have the correct dependencies since clearly it is working when you run locally.

Alternatively, if you want to ensure that you have the latest version of everything, you could run pip install --upgrade flask-socketio. This will install the latest version of Flask-SocketIO and the most up to date dependencies (including python-socketio and python-engineio). Then just regenerate your requirements.txt file and use it in your docker build.


The 400 (BAD REQUEST) indicates that there is a communication between Your Browser+JS and the Flask app.

I suspect an issue between The Flask App and Postgres.

Your Postgres has to be in the same network as you application server (the service you call "fortweet" in your docker-compose. Plus, you have give it a hostname so the app server can resolve it internally.

version: "3.8"services:  postgres:                               #    <=== same name here     image: postgres/postgres:11    networks:      - plutusnet                      #  <== same network  fortweet:    container_name: fortweet    build: ./    env_file:      - secret.env    networks:      - plutusnet                        #  <=== same network    links:      - db:postgres                      #    <== than here    ports:      - 8083:8083    restart: alwaysnetworks:  plutusnet:    name: plutus_network    driver: bridge`

Then the app must be configured to use "postgres:5432" to connect to DB.

Have a try and tell us.