gpt4 book ai didi

docker - 在docker中运行两个服务节点和python

转载 作者:行者123 更新时间:2023-12-02 12:04:04 24 4
gpt4 key购买 nike

FROM python:3.5 AS python-build
ADD . /test
WORKDIR /test
RUN pip install -r requirements.txt &&\
pip install oauth2client

FROM node:10-alpine AS node-build
WORKDIR /test
COPY --from=python-build ./test ./
WORKDIR /test/app/static
RUN npm cache verify && npm install && npm install sass -g &&\
sass --no-source-map scss/layout/_header.scss:css/layout/_header.css &&\
sass --no-source-map scss/layout/_footer.scss:css/layout/_footer.css &&\
sass --no-source-map scss/layout/_side_menu.scss:css/layout/_side_menu.css &&\
sass --no-source-map scss/layout/_error_component.scss:css/layout/_error_component.css &&\
sass --no-source-map scss/components/_input_box.scss:css/components/_input_box.css &&\
sass --no-source-map scss/components/_button.scss:css/components/_button.css &&\
sass --no-source-map scss/components/_loading_mask.scss:css/components/_loading_mask.css &&\
sass --no-source-map scss/components/_template_card.scss:css/components/_template_card.css &&\
sass --no-source-map scss/pages/_onboarding_app.scss:css/pages/_onboarding_app.css &&\
sass --no-source-map scss/pages/_choose.scss:css/pages/_choose.css &&\
sass --no-source-map scss/pages/_adapt.scss:css/pages/_adapt.css &&\
sass --no-source-map scss/pages/_express.scss:css/pages/_express.css &&\
sass --no-source-map scss/pages/_experience.scss:css/pages/_experience.css &&\
sass --no-source-map scss/pages/_features.scss:css/pages/_features.css &&\
sass --no-source-map scss/pages/_request_demo.scss:css/pages/_request_demo.css &&\
npm run build
WORKDIR /test/node-src
RUN npm install express


FROM python:3.5-slim
COPY --from=python-build /root/.cache /root/.cache
WORKDIR /test
COPY --from=node-build ./test ./
RUN apt-get update -yq \
&& apt-get install curl -yq \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash \
&& pip install -r requirements.txt
WORKDIR /test/node-src
EXPOSE 3000
CMD ["node", "server.js"] #RUN NODE SERVICE INSIDE NODE/SRC
WORKDIR /test
EXPOSE 9595
CMD [ "python3", "./run.py" ] #RUN PYTHON SERVICE INSIDE /TEST

我正在尝试在一个容器节点和python中运行两项服务,但只有一个正在运行,我想在kubernetes的一个容器中运行两项服务。

编辑:1
FROM python:3.5 AS python-build
ADD . /test
WORKDIR /test
RUN pip install -r requirements.txt &&\
pip install oauth2client

FROM node:10-alpine AS node-build
WORKDIR /test
COPY --from=python-build ./test ./
WORKDIR /test/app/static
RUN npm cache verify && npm install && npm install sass -g &&\
sass --no-source-map scss/layout/_header.scss:css/layout/_header.css &&\
sass --no-source-map scss/layout/_footer.scss:css/layout/_footer.css &&\
sass --no-source-map scss/layout/_side_menu.scss:css/layout/_side_menu.css &&\
sass --no-source-map scss/layout/_error_component.scss:css/layout/_error_component.css &&\
sass --no-source-map scss/components/_input_box.scss:css/components/_input_box.css &&\
sass --no-source-map scss/components/_button.scss:css/components/_button.css &&\
sass --no-source-map scss/components/_loading_mask.scss:css/components/_loading_mask.css &&\
sass --no-source-map scss/components/_template_card.scss:css/components/_template_card.css &&\
sass --no-source-map scss/pages/_onboarding_app.scss:css/pages/_onboarding_app.css &&\
sass --no-source-map scss/pages/_choose.scss:css/pages/_choose.css &&\
sass --no-source-map scss/pages/_adapt.scss:css/pages/_adapt.css &&\
sass --no-source-map scss/pages/_express.scss:css/pages/_express.css &&\
sass --no-source-map scss/pages/_experience.scss:css/pages/_experience.css &&\
sass --no-source-map scss/pages/_features.scss:css/pages/_features.css &&\
sass --no-source-map scss/pages/_request_demo.scss:css/pages/_request_demo.css &&\
npm run build
WORKDIR /test/node-src
RUN npm install express


FROM python:3.5-slim
COPY --from=python-build /root/.cache /root/.cache
WORKDIR /test
COPY --from=node-build ./test ./
RUN apt-get update -yq \
&& apt-get install curl -yq \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash \
&& pip install -r requirements.txt
WORKDIR /test/node-src
RUN npm install pm2 -g
EXPOSE 3000
CMD pm2 start server.js #RUN NODE SERVICE INSIDE NODE/SRC
WORKDIR /test
EXPOSE 9595
CMD [ "python3", "./run.py" ] #RUN PYTHON SERVICE INSIDE /TEST

我还尝试了节点的pm2服务。

最佳答案

您不希望实现的目标是推荐的设计。通常,docker容器应运行单个服务。结果,尽管没有可能,也可以使用包装脚本或诸如supervisord之类的工具在docker中使用内置方法来实现此目的,但您可以在容器内部管理多个服务,

或至于docs :(我选择了supervisord选项,因为在我看来,它比包装脚本方式更干净,更易于管理)

Use a process manager like supervisord. This is a moderately heavy-weight approach that requires you to package supervisord and its configuration in your image (or base your image on one that includes supervisord), along with the different applications it manages. Then you start supervisord, which manages your processes for you. Here is an example Dockerfile using this approach, that assumes the pre-written supervisord.conf, my_first_process, and my_second_process files all exist in the same directory as your Dockerfile.

FROM ubuntu:latest
RUN apt-get update && apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY my_first_process my_first_process
COPY my_second_process my_second_process
CMD ["/usr/bin/supervisord"]


https://docs.docker.com/config/containers/multi-service_container/

您当前在Dockerfile中使用的是 multisage build,到目前为止,它是 ,而不是

关于docker - 在docker中运行两个服务节点和python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56482613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com