部署含ODBC驱动的Flask应用(基于tiangolo/uwsgi-nginx:python3.7)后服务未启动
问题:部署带ODBC驱动的Flask应用失败
使用tiangolo/uwsgi-nginx:python3.7镜像部署Flask应用,未安装ODBC驱动时服务运行正常,但添加ODBC驱动安装步骤后,镜像构建成功但服务无法启动。
Dockerfile 内容
#Base Docker image with uWSGI and Nginx for Flask applications in a single container FROM tiangolo/uwsgi-nginx:python3.7 #By default, the application runs on port 80, you can choose a different port by uncommenting the LISTEN PORT and EXPOSE ENV LISTEN_PORT 5000 EXPOSE 5000 # URL under which static (not modified by Python) files will be requested # They will be served by Nginx directly, without being handled by uWSGI ENV STATIC_URL /static # Absolute path in where the static files wil be ENV STATIC_PATH /app/static # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured in this case it will be 0) # ENV STATIC_INDEX 1 ENV STATIC_INDEX 0 # Add app COPY ./classes /app/classes/ COPY ./models /app/models/ COPY ./config /app/config/ COPY ./microservices /app/microservices/ COPY ./templates /app/templates/ COPY ./main.py /app/main.py COPY ./inputs /app/inputs/ # Add API files COPY ./uwsgi.ini /app/uwsgi.ini COPY ./requirements.txt /app/requirements.txt # Define working directory WORKDIR /app ENV FLASK_DEBUG 1 ENV FLASK_ENV development ENV INPUT_PATH=/app/inputs # Install requirements RUN /usr/local/bin/python -m pip install --upgrade pip RUN pip3 install -r requirements.txt #RUN pip install --no-cache-dir -r requirements.txt # Install ODBC Driver ENV ACCEPT_EULA=Y RUN apt-get update -y && apt-get update \ && apt-get install -y --no-install-recommends curl gcc g++ gnupg unixodbc-dev RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - RUN curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list RUN apt-get update RUN mv /etc/apt/sources.list.d/mssql-release.list ~/ RUN apt-get update RUN apt-get install unixodbc RUN mv ~/mssql-release.list /etc/apt/sources.list.d/ RUN apt-get update RUN apt-get install -y msodbcsql17 RUN apt-get install -y mssql-tools RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc # Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. ENV PYTHONPATH=/app # Move the base entrypoint to reuse it RUN mv /entrypoint.sh /uwsgi-nginx-entrypoint.sh # Copy the entrypoint that will generate Nginx additional configs COPY ./entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] # Run the start script provided by the parent image tiangolo/uwsgi-nginx which in turn will start Nginx and uWSGI CMD ["/start.sh"]
entrypoint.sh 内容
#! /usr/bin/env sh set -e /uwsgi-nginx-entrypoint.sh # Get the URL for static files from the environment variable USE_STATIC_URL=${STATIC_URL:-'/static'} # Get the absolute path of the static files from the environment variable USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} # Get the listen port for Nginx, default to 80 USE_LISTEN_PORT=${LISTEN_PORT:-80} if [ -f /app/nginx.conf ]; then cp /app/nginx.conf /etc/nginx/nginx.conf else content_server='server {\n' content_server=$content_server" listen ${USE_LISTEN_PORT};\n" content_server=$content_server' location / {\n' content_server=$content_server' try_files $uri @app;\n' content_server=$content_server' }\n' content_server=$content_server' location @app {\n' content_server=$content_server' include uwsgi_params;\n' content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' content_server=$content_server' }\n' content_server=$content_server" location $USE_STATIC_URL {\n" content_server=$content_server" alias $USE_STATIC_PATH;\n" content_server=$content_server' }\n' # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) if [ "$STATIC_INDEX" = 1 ] ; then content_server=$content_server' location = / {\n' content_server=$content_server" index $USE_STATIC_URL/index.html;\n" content_server=$content_server' }\n' fi content_server=$content_server'}\n' # Save generated server /etc/nginx/conf.d/nginx.conf printf "$content_server" > /etc/nginx/conf.d/nginx.conf fi # For Alpine: # Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH # Otherwise uWSGI can't import Flask if [ -n "$ALPINEPYTHON" ] ; then export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$ALPINEPYTHON/site-packages:/usr/lib/$ALPINEPYTHON/site-packages fi exec "$@"
内容的提问来源于stack exchange,提问作者arnau infante pinés
相关产品推荐
相关产品推荐

