Using APIStar with docker-compose

Hi all,

Apologies, I’m a bit new to this discuss board and not sure if this is the best area to discuss issues using the framework. If so, just point me in the right direction and I’ll be happy to close :slight_smile:

Anyways, I’ve been using apistar and loving it, however when setting it up in a docker, I end up getting a HTTP 104 Connection Reset by Peer response when trying to hit a route that I have setup. So the reason why I think this is an apistar issue is with the exact same setup, I can run http.server and serve on the same port just fine.

To give a bit of context, my dockerfile is below

FROM python:3
COPY ./ /app
RUN pip install -r /app/requirements.txt
CMD python3 /app/src/

and my simple helloworld app

def welcome(params:http.QueryParams) -> dict:
    name = dict(WelcomeParams(**dict(params)))['name']
    if name is None:
        return {'message': 'Welcome to API Star!'}
    return {'message': 'Welcome to API Star, %s!' % name}

routes = [
    Route('/', method='GET', handler=welcome),

app = App(routes=routes)

if __name__ == '__main__':
    app.serve('localhost', 5000, debug=True)

any idea what might be the issue here or why apistar would cause this problem? I’d be surprised if no one was running apistar in docker containers

This is definitely the place to discuss these kind of things! Welcome.

I haven’t seen any issues in using docker myself, although I did it just as an experiment. I didn’t use the Werkzeug development server in my docker container though. It’s not a production server, and you may get better mileage using something like Gunicorn or uWSGI instead.

I found this article in conjunction with the Gunicorn docs helpful in getting a setup working.

If it’s docker-compose you are using, you may also want to show the docker-compose.yml file. Make sure the right ports are exposed.

You may also want to listen on instead of localhost during development, as localhost will use DNS (not sure what the python:3 image has for DNS by default) and it will only listen for requests made within the running container. Chances are, you might be running the container and making requests outside of it.