我想在单个 docker 容器中运行:
两个应用程序都将在 NGINX 的同一端口上公开。我已经在单独的 docker 容器(没有 nginx)中测试了这两个应用程序,它们可以工作,但在此配置中不起作用!我估计是CMD命令没有正确使用!任何帮助将不胜感激!
PS:我知道这不是一个好的做法!在多个 Docker 容器中运行应用程序是更受欢迎的,但我真的需要测试这个架构!您可以在下面检索所有主要组件!
from fastapi import FastAPI
import uvicorn
app = FastAPI()
@app.get("/echo")
def get_hello_word() -> str:
return "Hello world from Python!"
#* Echo back the input
#* @get /echo
get_hello_world <- function() {
return("Hello world from R!")
}
events {
worker_connections 1024;
}
http {
server {
listen 8000;
location /fastapi {
proxy_pass http://localhost:81/;
}
location /plumber {
proxy_pass http://localhost:8000/;
}
}
}
fastapi==0.110.0
uvicorn==0.27.1
FROM python:3.8.19
# Install nginx
RUN apt-get update && apt-get install -y \
nginx
COPY nginx.conf /etc/nginx/nginx.conf
# Install Python
WORKDIR /app
COPY fastapi_app.py fastapi_app.py
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
#Install R dependencies
RUN apt-get update && apt-get install -y \
r-base \
libssl-dev \
libcurl4-gnutls-dev
RUN R -e "install.packages('plumber')"
COPY plumber.R plumber.R
# TODO: ADD CMD command
您需要使用像supervisor
这样的流程控制系统您可以将nginx、fastapi和plumber包装在supervisor配置中,并在CMD命令中将supervisor作为进程运行,它将控制下面的任务来运行nginx、fastapi和plumber应用程序。