简体   繁体   中英

docker-compose flask network issue

I have a python flask project which is supposed to be a web app for an internal network. It's in a docker image which is started with a docker-compose file.

Sometimes when I run it, the flask server doesn't get messages from the outside world. I figure it has to be a problem with the docker network that docker-compose automatically creates. Whenever this problem occurs I have to restart the box then bring the container back up, and it fixes itself.

Has anyone else seen this?

When I say it doesn't see connections from outside the box I mean HTTP requests never make it to the flask server. I can attempt to go to the URL corresponding to the flask server from a different machine and the flask server sees nothing. However, if I attempt to send an HTTP GET request from inside the box (not inside the container, but on the box the container is running on) the flask server responds.

So this leads me to believe docker-compose is creating a docker network which isn't configured correctly to allow the container to listen to outside requests.

Here's my docker compose file:

version: '3.7'
services:
  falcon:
    image: "company.com/internal/falcon:0.1"
    container_name: falcon
    env_file:
      - ~/.env
    ports:
      - "80:80"
    volumes:
      - ${REPOS}/falcon:/app
    command: /conda/bin/falcon start

This hasn't been tested extensively, but it seems to have solved the problem:

version: '3.7'
services:
  falcon:
    image: "company.com/internal/falcon:0.1"
    container_name: falcon
    network_mode: bridge  # also tried host, I think bridge is right.

Another solution seemed to omit the network_mode above and put this down below:

networks:
    default:
        external:
            name: prod_default

I still don't know why it happened, but both of these solutions seemed to fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM