3

yet another docker/flask question. I'm having problems connecting to my flask app from another container in docker-compose.

My dockerfile sets up a flask app like:

COPY ./ /app/

WORKDIR /app

RUN find -name "*.pyc" -delete && \
    pip3 install -r requirements.txt

EXPOSE 5000

CMD ["python3", "app.py"]

The app runs on 0.0.0.0:5000, the docker-compose.yml looks like this:

version: '3'

services:

  app:
    build: .
    ports:
      - "5000:5000"

  test:
    image: alpine:3.8

Now after docker-compose up I can curl from the host like:

curl -i http://0.0.0.0:5000
...
200 - ok

but if I jump into the test container I get a 404:

docker-compose run test sh
# apk --update add curl
# curl -i http://app:5000
...
404 - not found

Actually these 2 containers should see each other, and indeed when I look at the logs of app I can see the requests from test comming in. But they are answered with 404.

What am I doing wrong here?

Btw, I have a minimal example here: https://github.com/mRcSchwering/flask_docker-compose

0

1 Answer 1

6

This is because your config

app.config['SERVER_NAME'] = '0.0.0.0:5000'

Your Flask thinks its name is 0.0.0.0:5000, therefore not responding to others.

To verify, call curl -H Host:0.0.0.0:5000 -i http://app:5000 from test.

You can remove this config and run the server with

app.run(host='0.0.0.0')
Sign up to request clarification or add additional context in comments.

2 Comments

That's it. Thanks. I always thought setting server_name is the same as setting host and port (arguments)
Also, make sure to docker-compose up <service> not docker-compose run <service>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.