Report this

What is the reason for this report?

Flask Docker container SocketIO Issues

Posted on December 8, 2020

I have a Flask application that uses SocketIO to fetch data from Postgres live.

My socketio in JS is like this:

var socket = io.connect('http://localhost:8083') The app works fine when I run this locally.

The problem arouses when I use docker-compose to host my Flask app, localhost is no more recognized as my docker-compose uses a bridge network.

My docker-compose is as such:

version: "3.8"

services:
  fortweet:
    container_name: Fortweet
    build: ./
    env_file:
      - secret.env
    networks:
      - plutusnet
    ports:
      - 8083:8083
    restart: always

networks:
  plutusnet:
    name: plutus_network
    driver: bridge

I’ve also tried to use var socket = io.connect('http://fortweet:8083') but my socket connection still doesn’t work.

I have also a Postgres DB in the plutus_network hosted on my server. I don’t know if this information is useful but I’m just mentioning it here.

Can anyone help me ?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.