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 ?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @th3pl4gu33,

Are you running your JS application directly on the host or on inside a container connected to the same Docker network?

If this is the case, what I could suggest is running netstat -plant after starting the Flask Docker container to see if the port is exposed to the host correctly.

Another thing that I could suggest is running docker inspect for your network to see if the Flask container is correctly connected. Also maybe try to set the container name to fortweet rather than Fortweet to avoid any problems due to case sensitivity.

Let me know how it goes. Regards, Bobby

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.