Docker部署集成Julia Wflow模型的Flask应用时遭遇Wflow包未找到错误的求助
Docker部署集成Julia Wflow模型的Flask应用时遭遇Wflow包未找到错误的求助
我正在尝试给我的Flask应用构建Docker容器,应用里需要运行一款名为Wflow的开源水文模型,它是通过Julia命令来执行的。
Flask中调用Wflow的实现代码
julia_process = subprocess.Popen("julia", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) # Julia commands to be executed julia_commands = f""" using Wflow Wflow.run("{toml_path}") """ # Send the commands to Julia through the process's standard input output, errors = julia_process.communicate(julia_commands)
遇到的问题
- 本地环境下,带Julia Wflow命令的应用运行完全正常
- 但构建Docker容器后,明明已经在容器里安装了Wflow包,却始终弹出Julia Wflow包未找到的错误
- 我试了好几种命令都没法解决,已经卡在这里好一阵子了
我当前的Dockerfile内容
# syntax=docker/dockerfile:1 # Use Mambaforge as the base image for Conda support FROM condaforge/mambaforge:latest # Set maintainer info LABEL maintainer="Maarten Pronk <maarten.pronk@deltares.nl>" # Copy .cdsapirc to root directory for configuration COPY .cdsapirc /root/.cdsapirc # Create application directory RUN mkdir -p /app WORKDIR /app # Set the default shell for proper Conda usage SHELL ["/bin/bash", "-c"] # Install system dependencies RUN apt-get update && apt-get install -y \ g++ git gcc gunicorn curl libcurl4-openssl-dev \ && rm -rf /var/lib/apt/lists/* # Create HydroMT-WFlow environment with Julia support RUN mamba create -n hydromt-wflow -c conda-forge \ hydromt_wflow python=3.11 julia gunicorn -y # Set Conda's default environment for all future commands ENV CONDA_DEFAULT_ENV=hydromt-wflow ENV PATH=/opt/conda/envs/hydromt-wflow/bin:$PATH ENV JULIA_DEPOT_PATH="/opt/julia" # Ensure pip is installed inside the Conda environment RUN conda run -n hydromt-wflow python -m ensurepip && \ conda run -n hydromt-wflow python -m pip install --upgrade pip # Copy requirements.txt and install dependencies inside Conda environment COPY requirements.txt /app/requirements.txt RUN test -f /app/requirements.txt && conda run -n hydromt-wflow pip install --no-cache-dir -r requirements.txt || echo "No requirements.txt found" RUN julia -e 'println("Starting Wflow installation..."); \ using Pkg; \ Pkg.update(); \ println("Registry updated"); \ Pkg.add(name="Wflow"); \ println("Wflow installed successfully"); \ using Wflow; \ println("Wflow loaded and verified")' # Copy source code into container COPY . . # Expose the application port EXPOSE 5000 ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "hydromt-wflow"] CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "5", "--timeout", "5000", "--log-level", "debug", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
我额外尝试过的Docker命令
我还在Dockerfile里试过用以下命令来安装Wflow:
RUN julia -e 'using Pkg; Pkg.develop(PackageSpec(url="https://github.com/Deltares/Wflow.jl.git"))' RUN julia -e 'using Pkg; \ Pkg.develop(PackageSpec(url="https://github.com/Deltares/Wflow.jl.git")); \ Pkg.instantiate(); \ using Wflow; \ println("Wflow successfully loaded")'
真心希望能得到大家的帮助,我已经卡在这里好久了!
备注:内容来源于stack exchange,提问作者Basit
相关产品推荐
相关产品推荐

