I am having a challenge solving an error in Docker. I am building a Flask app and want to deploy it on Docker containers, but when I run my successfully created image using docker run
, I get the error Failed to find attribute 'app' in 'gossip_app'
.
Here is the full error message from docker logs
:
[2020-10-30 09:54:41,411] INFO in __init__: Tinker ChatApp
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> a6664359912e, Add user table
INFO [alembic.runtime.migration] Running upgrade a6664359912e -> 6b7e8489b0ee, Add post table
INFO [alembic.runtime.migration] Running upgrade 6b7e8489b0ee -> a8b409f2c772, Add fields to user table
INFO [alembic.runtime.migration] Running upgrade a8b409f2c772 -> 2a3289732dbc, add followed field in user table
INFO [alembic.runtime.migration] Running upgrade 2a3289732dbc -> d055880868f7, Add language field to post table
[2020-10-30 09:54:42,426] INFO in __init__: Tinker ChatApp
compiling catalog app/translations/sw/LC_MESSAGES/messages.po to app/translations/sw/LC_MESSAGES/messages.mo
compiling catalog app/translations/zh/LC_MESSAGES/messages.po to app/translations/zh/LC_MESSAGES/messages.mo
[2020-10-30 09:54:42 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-30 09:54:42 +0000] [1] [INFO] Listening at: http://0.0.0.0:5000 (1)
[2020-10-30 09:54:42 +0000] [1] [INFO] Using worker: sync
[2020-10-30 09:54:42 +0000] [12] [INFO] Booting worker with pid: 12
Failed to find attribute 'app' in 'gossip_app'.
[2020-10-30 09:54:42 +0000] [12] [INFO] Worker exiting (pid: 12)
[2020-10-30 09:54:42 +0000] [1] [INFO] Shutting down: Master
[2020-10-30 09:54:42 +0000] [1] [INFO] Reason: App failed to load.
My Flask app is structured as:
1_work_gossip_chat_app
|------------app/
|------------boot.sh
|------------Dockerfile
|------------config.py
|------------tinker.py
|------------requirements.txt
I created my image by updating the Dockerfile
and the boot.sh
file which acts as an executable, as seen below:
Dockerfile
FROM python:3.8-alpine
RUN adduser -D gossip_app
WORKDIR /home/software_development/python/current_projects/1_work_gossip_chat_app
COPY requirements.txt requirements.txt
RUN python -m venv gossip_app
RUN gossip_app/bin/python3 -m pip install --upgrade pip
RUN \
# install psycopg2 dependancies
apk update && \
apk add postgresql-dev gcc python3-dev musl-dev && \
# then install your requirements
gossip_app/bin/pip3 install -r requirements.txt && \
gossip_app/bin/pip3 install gunicorn pymysql
COPY app app
COPY migrations migrations
COPY tinker.py config.py boot.sh ./
RUN chmod +x boot.sh
ENV FLASK_APP tinker.py
RUN chown -R gossip_app:gossip_app ./
USER gossip_app
EXPOSE 5000
ENTRYPOINT [ "./boot.sh" ]
boot.sh
#!/bin/sh
source gossip_app/bin/activate
flask db upgrade
flask translate compile
exec gunicorn -b :5000 --access-logfile - --error-logfile - gossip_app:app
I understand that from the error gunicorn
is telling me that there is no Flask app instance in gossip_app
. gossip_app
to the best of my knowledge is the new user and also the new owner of the files and directories.
What could I be getting wrong when creating this container?
I have looked at several examples of how to build and run an image in Docker such as this and everything works very well, except for the one error I am admittedly struggling to debug for days on end.