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服务。
答案 0 :(得分:2)
您不打算采用什么方法来实现它。通常,docker容器应运行单个服务。结果,尽管没有可能,也可以使用包装脚本或supervisord之类的工具在docker中使用内置方法来使它正常工作,但是您可以在容器内管理多个服务-
或docs :(我选择了supervisord选项,因为在我看来,它比包装脚本方式更干净,更易于管理)
使用流程管理器,例如supervisor。这是一个适度的 需要您打包supervisord及其 映像中的配置(或基于包含以下内容的映像进行配置) 主管),以及它管理的不同应用程序。然后 您将开始成为主管,该主管将为您管理流程。这是 使用此方法的示例Dockerfile,假设 预先编写的supervisord.conf,my_first_process和my_second_process 所有文件都与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,到目前为止,不是您想要的。