0

Firstly thank you for your time. I can't get any date from an API in my docker container. Neverveless I can if I'm in the container with a curl command but not from postman or a curl command if I 'm not in the container I don't know why, somebody have a solution for me ? :(

I mapped the port, docker-compose ps :

python  /bin/sh -c ./src/server.py - ...   Up      0.0.0.0:9090->9090/tcp

Above my docker-compose file :

'''

# Docker Compose 

version: "3"

# Docker Containers 

services:
  # python 

  python:
    build: ./docker/python
    working_dir: /root/app
    command: ./src/server.py
    environment:
      - SERVER_PORT=9090
    ports:
      - 9090:9090
    volumes:
      - .:/root/app
      - ./.bash-history/python:/root/.bash_history

'''

My python server :

'''

#!/usr/local/bin/python

import sys
sys.path.append('/root/app/python_modules')

from flask import Flask, json



companies = [{"id": 1, "name": "Company One"}, {"id": 2, "name": "Company Two"}]

api = Flask(__name__)

@api.route('/companies', methods=['GET'])
def get_companies():
  return json.dumps(companies)

if __name__ == '__main__':
    api.run(host='', port=9090, debug=True)

'''

  • 1
    can you provide the curl commands you are using? – clemens Jun 10 '20 at 08:10
  • 1
    Does setting `host='0.0.0.0'` help? (See also [Deploying a minimal flask app in docker - server connection issues](https://stackoverflow.com/q/30323224/10008173).) – David Maze Jun 10 '20 at 10:15
  • Thank you so much you solved my problem I use the curl command : ''' curl GET http://localhost:9090/companies ''' – ptitouriste Jun 10 '20 at 14:55

0 Answers0