1

I am currently working with Docker and a simple Flask website to which I want to send images. For this I'm working on port 8080, but the mapping from docker to host is not working properly as I am unable to connect. Could someone explain to me what I am doing wrong?

docker-compose.yml

version: "2.3"
services:
  dev:
    container_name: xvision-dev
    build:
      context: ./
      dockerfile: docker/dev.dockerfile
    working_dir: /app
    volumes:
      - .:/app
      - /path/to/images:/app/images
    ports:
      - "127.0.0.1:8080:8080"
      - "8080"
      - "8080:8080"

dev.dockerfile

FROM tensorflow/tensorflow:latest

WORKDIR /app

COPY requirements.txt ./
RUN pip install -r requirements.txt

RUN apt update && apt install -y python-tk

EXPOSE 8080

CMD ["python", "-u", "app.py"]

app.py

@APP.route('/test', methods=['GET'])
def hello():
    return "Hello world!"
def main():
    """Start the script"""
    APP.json_encoder = Float32Encoder
    APP.run(host="127.0.0.1", port=os.getenv('PORT', 8080))

I start my docker with docker-compose up, this gives the output: Running on http://127.0.0.1:8080/ (Press CTRL+C to quit).

But when I do a get request to 127.0.0.1:8080/test I get that there is no response.

I have also tried docker-compose run --service-port dev as some people have suggested online but this says that there is no service dev.

Can someone help me for what I am doing wrong?

Anna Jeanine
  • 3,975
  • 10
  • 40
  • 74
  • I'm not that experienced in python or flask but it seems like your server never starts as you're never calling `main`. – tkausl Nov 14 '18 at 13:23
  • The server is starting as based on the output provided, the code included seems incomplete though. – Uku Loskit Nov 14 '18 at 13:25

1 Answers1

4

Use:

APP.run(host="0.0.0.0", port=os.getenv('PORT', 8080))

Using only:

ports:

  - "8080:8080"

is enough

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93