-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Thank you so much for all of your hard work maintaining this project. I ran into an interesting problem when trying to deploy a Dockerized app to AWS using some of these images, just wanted to report my experience, see if there was anything you wanted to do about it or could advise on. I'll try my best to provide relevant details, but please let me know if there is other useful information that I can provide.
Several years ago, I launched a Django app on AWS using the stable release. I recently needed to make some upgrades to the app, and switched to py3.11.10-gdal3.6.2.
Running locally on my MacBook Pro, everything was fine. However, when I pushed the app up to an AWS EC2 instance, it started failing with the error message pyenv: gunicorn: command not found
. gunicorn
is installed via inclusion in a requirements.txt
file.
Eventually, I was able to get a successful deployment by switching to andrejreznik/python-gdal:py3.10.0-gdal3.2.3 so that's good news since I am now unblocked, but I did also experiment with another one of the recent tags of this image and had the same problem, so it's not an entirely isolated problem.
Here is the initial Dockerfile
that resulted in the failing deployment:
FROM andrejreznik/python-gdal:py3.11.10-gdal3.6.2
ENV PYTHONUNBUFFERED 1
RUN pip install --upgrade pip
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install postgresql-15 postgresql-server-dev-15 -y
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
ARG ALLOWED_HOSTS
ARG AWS_ACCESS_KEY_ID
ARG AWS_S3_CUSTOM_DOMAIN
ARG AWS_SECRET_ACCESS_KEY
ARG AWS_STORAGE_BUCKET_NAME
ARG AWS_SES_ACCESS_KEY_ID
ARG AWS_SES_SECRET_ACCESS_KEY
ARG CORS_ALLOWED_ORIGINS
ARG DATABASE_HOST
ARG DATABASE_NAME
ARG DATABASE_PASSWORD
ARG DATABASE_PORT
ARG DATABASE_USER
ARG SECRET_KEY
ENV ALLOWED_HOSTS=${ALLOWED_HOSTS}
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ENV AWS_S3_CUSTOM_DOMAIN=${AWS_S3_CUSTOM_DOMAIN}
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ENV AWS_STORAGE_BUCKET_NAME=${AWS_STORAGE_BUCKET_NAME}
ENV AWS_SES_ACCESS_KEY_ID=${AWS_SES_ACCESS_KEY_ID}
ENV AWS_SES_SECRET_ACCESS_KEY=${AWS_SES_SECRET_ACCESS_KEY}
ENV CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS}
ENV DATABASE_HOST=${DATABASE_HOST}
ENV DATABASE_NAME=${DATABASE_NAME}
ENV DATABASE_PASSWORD=${DATABASE_PASSWORD}
ENV DATABASE_PORT=${DATABASE_PORT}
ENV DATABASE_USER=${DATABASE_USER}
ENV SECRET_KEY=${SECRET_KEY}
EXPOSE 8000
RUN ["python", "manage.py", "collectstatic", "--noinput"]
RUN ["python", "manage.py", "migrate"]
RUN ["python", "manage.py", "create_organization_groups"]
CMD ["gunicorn", "--workers=4", "--bind=:8000", "my_app.wsgi"]
and the associated requirements.txt
:
boto3==1.16.18
django==3.1
django-ckeditor==6.0.0
django-cors-headers==3.5.0
django-filter==2.4.0
django-import-export>=2.5.0
django-ses==1.0.3
django-simple-history==2.11.0
django-storages==1.10.1
djangorestframework==3.11.1
djangorestframework-gis==0.16
dj-database-url==0.5.0
gunicorn==20.0.4
Pillow==7.2.0
psycopg2-binary==2.9.10
mysql-connector-python>=8.0.21
timezonefinder>=4.2.0
pytz>=2020.1
and again, I was able to get things working by making the following changes to the Dockerfile
:
- changed OS to
andrejreznik/python-gdal:py3.10.0-gdal3.2.3
- changed PostgreSQL version to 13 (highest available for that OS)
In the course of working on this, I also experimented with installing gunicorn
via apt-get
in the Dockerfile
rather than requirements.txt
, in which case I then started getting the error:
File "/code/my_app/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'