docker容器多服务(不推荐)

时间:2022-07-27 17:01:32

1、最常用方式配置进程管理工具Supervisor

2、最简单的就是把多个启动命令放到一个启动脚本里面,启动的时候直接启动这个脚本

第一种方式:

1、构建基础镜像

FROM lmurawsk/python2.7
MAINTAINER adolf "zhangmingcheng@pansoft.com"
RUN apt-get update && apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
RUN mkdir -p /opt/jdk
ADD jdk /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:$JAVA_HOME/bin
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple imagehash
ADD web.py-0.38 /opt/web.py-0.38
WORKDIR /opt/web.py-0.38/
RUN easy_install web.py

2、配置 supervisord.conf

[supervisord]
nodaemon=true [program:webpy]
command=python /root/imagedhash/rest.py 0.0.0.0:8888
stdout_logfile=/root/log/rest.log
stderr_logfile=/root/log/rest.log [program:imagecheck]
command=java -jar /root/imagedhash/app.jar
stdout_logfile=/root/log/checks.log
stderr_logfile=/root/log/checks.log

3、构建镜像

FROM imagecheck:init
MAINTAINER adolf "zhangmingcheng@pansoft.com"
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN mkdir -p /root/imagedhash
RUN mkdir -p /root/images
RUN mkdir -p /root/log
ADD rest.py /root/imagedhash
WORKDIR /root/imagedhash
ADD ShowImage.jar app.jar
EXPOSE 8888 8080
CMD ["/usr/bin/supervisord"]

第二种方式:

1、构建基本镜像

docker容器多服务(不推荐)

Dockerfile

FROM lmurawsk/python2.7
MAINTAINER adolf "zhangmingcheng@pansoft.com"
RUN mkdir -p /opt/jdk
ADD jdk /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:$JAVA_HOME/bin
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple imagehash
ADD web.py-0.38 /opt/web.py-0.38
WORKDIR /opt/web.py-0.38/
RUN easy_install web.py

2、构建相似影像查重镜像

Dockerfile

FROM imagecheck:init
MAINTAINER adolf "zhangmingcheng@pansoft.com"
RUN mkdir -p /root/imagedhash
RUN mkdir -p /root/images
ADD rest.py /root/imagedhash
WORKDIR /root/imagedhash
ADD ImagesCheck.jar app.jar
ADD dhash.sh dhash.sh
EXPOSE 8080
CMD ["/root/imagedhash/dhash.sh","run"]

dhash.sh

nohup python rest.py 8888 > out.log 2>&1 &
java -jar app.jar

rest.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-01-04
# @Author : zhangmingcheng import web
from PIL import Image
import imagehash
import glob
import json
import os,sys urls=(
'/images/getImageDhash','get_imagedhash'
)
app = web.application(urls,globals()) class get_imagedhash:
def GET(self):
path = web.input().path
image = Image.open(path)
h = str(imagehash.dhash(image))
return h