ray Version: 2.42.1
python = 3.10.12,
I have multiple deployments, but their environments need to be isolated. However, I don’t want to install them at runtime through pip because it’s too time-consuming and unstable. So I installed the environment on Docker Image, but I can’t run it perfectly on Ray Server
this is Dockerfile
# 使用 Miniconda 作为基础镜像
FROM continuumio/miniconda3
# 设置工作目录
WORKDIR /app
# 创建 Conda 环境
RUN conda create --name kolors python=3.10.12
RUN echo "conda activate kolors" >> ~/.bashrc
ENV PATH /opt/conda/envs/kolors/bin:$PATH
# 设置 pip 镜像源为国内源(比如阿里云镜像)
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 安装 Ray 和其他依赖
RUN pip install --upgrade pip
# 将本地的 requirements.txt 复制到容器中的 /app 目录
COPY requirements.txt /app/requirements.txt
# 安装项目的 Python 依赖
RUN pip install -r /app/requirements.txt
# 只需保持环境配置,不需要启动 app.py
# 最终,容器本身不启动任何程序,只需提供环境
CMD ["/bin/bash"]
this is requirements.txt
emoji
### this is ray.remoto
import ray
runtime_env = {"image_uri": "localhost/kolor_podman_ray"}
ray.init(runtime_env=runtime_env)
@ray.remote
def f():
import emoji
return emoji.emojize('Python is :thumbs_up:')
print(ray.get(f.remote()))
this is successful
this is ray serve
import ray
from ray import serve
from fastapi import FastAPI
import ray
# 创建 FastAPI 应用
app = FastAPI()
# 定义 Ray Serve 部署类
@serve.deployment(num_replicas=2)
@serve.ingress(app)
class EmojiService:
def __init__(self):
pass
@app.get("/emoji")
def get_emoji(self):
import emoji
# 处理请求,返回表情字符串
return emoji.emojize('Python is :thumbs_up:')
# 绑定服务
app= EmojiService.options(ray_actor_options={"runtime_env": {"image_uri": "localhost/kolor_podman_ray"}}).bind()
this is fail: