Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reloading doesn't work inside Docker container #142

Closed
nleroy917 opened this issue Aug 8, 2021 · 3 comments
Closed

Hot reloading doesn't work inside Docker container #142

nleroy917 opened this issue Aug 8, 2021 · 3 comments

Comments

@nleroy917
Copy link

I've having issues getting the live reloading to work when running the functions-framework inside a Docker container. I'm trying to set up a development environment using docker-compose. I am using the solution implemented here to be able to call all functions from one endpoint.

This is my Dockerfile:

# use alpine linux with standard python-3.9
FROM python:3.9-alpine

# install necessities and c compilers
RUN apk update && apk upgrade && apk add g++ gcc

# open up port 5000
EXPOSE 5000

# set working directory
WORKDIR /server

# copy files over
COPY requirements.txt /server/requirements.txt

# set env variables
ENV FLASK_ENV development
ENV DEBUG true

# install python dependencies
RUN pip install -r requirements.txt

# spin up gcloud functions server
CMD ["functions-framework", "--target=dispatcher", "--port=5000", "--debug"]

And inside docker-compose.yml I have this:

    # functions server
    functions:
        container_name: functions
        restart: always
        ports:
            - "5000:5000"
        build:
            context: ./
            dockerfile: ./Dockerfile.dev
        volumes:
          - ./spottydata:/server/spottydata
          - ./main.py:/server/main.py
        networks:
          - backend

I specified main.py as a mounted volume so it can see changes made during deployment, but nothing I do to that file triggers a hot reload. I wasn't sure if there were any examples running this in a docker container for development.

Thanks!

@di
Copy link
Member

di commented Aug 9, 2021

Hi @nleroy917, sorry you're having trouble.

I wasn't sure if there were any examples running this in a docker container for development.

There wasn't, so I added these in #143. With this minimal example, live reloading works as expected for me. Could you try to reproduce with that example and work backwards to your current setup?

I suspect the issue might be that you're mounting a single file as a volume, rather than a directory.

# set env variables
ENV FLASK_ENV development
ENV DEBUG true

You also shouldn't need to set these.

Also, PS: using alpine images for Python is generally not recommended: https://pythonspeed.com/articles/alpine-docker-python/

@nleroy917
Copy link
Author

Hey @di! Thanks for the detailed example. I swapped out the alpine image for slim and that didn't work, but when I changed my volume mounts to:

        volumes:
          - .:/server

hot reloading started working again. I've used flask inside docker-compose before with alpine images and mounting single files -- hot reloading has never been an issue, so that was odd.

Anyways, thank you for the help!

@di
Copy link
Member

di commented Aug 9, 2021

Yeah, I think ultimately it's this issue: moby/moby#15793. Glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants