FROM ubuntu:14.04.2
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -y update && apt-get upgrade -y
RUN apt-get install python build-essential python-dev python-pip python-setuptools -y
RUN apt-get install libxml2-dev libxslt1-dev python-dev -y
RUN apt-get install libpq-dev postgresql-common postgresql-client -y
RUN apt-get install openssl openssl-blacklist openssl-blacklist-extra -y
RUN apt-get install nginx -y
RUN pip install "pip>=7.0"
RUN pip install virtualenv uwsgi
ADD canonicaliser_api /home/ubuntu/canonicaliser_api
ADD config_local.py /home/ubuntu/canonicaliser_api/config/config_local.py
RUN virtualenv /home/ubuntu/canonicaliser_api/venv
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && pip install -r /home/ubuntu/canonicaliser_api/requirements.txt
RUN export CFLAGS=-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && cd /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/ && python setup.py build_ext --inplace
RUN cp /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/canonicaliser/cython_extensions/*.so /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions
RUN rm -rf /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/canonicaliser
RUN rm -r /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/build
RUN mkdir /var/run/flask-uwsgi
RUN chown -R www-data:www-data /var/run/flask-uwsgi
RUN mkdir /var/log/flask-uwsgi
RUN touch /var/log/flask-uwsgi/dqs_canon.log
RUN chown -R www-data:www-data /var/log/flask-uwsgi
RUN mkdir /etc/flask-uwsgi
ADD configs/new-canon/flask-uwsgi/flask-uwsgi.conf /etc/init/
ADD configs/new-canon/flask-uwsgi/flask-uwsgi.ini /etc/flask-uwsgi/
EXPOSE 8888
CMD service flask-uwsgi restart
# RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# CMD service nginx start
当我尝试运行此docker时,我收到错误消息:
flask-uwsgi: unrecognized service
所以我最后取消注释最后两行,以便nginx启动并使docker进程保持活动状态。然后我ssh进入它进行调试。
docker exec -it 20b2ff3a4cac bash
现在,当我尝试运行该服务时,这是同样的问题,我找不到任何遗漏的步骤。也许不允许在docker中启动服务?
root@30b2ff3a4cac:/# service flask-uwsgi start
flask-uwsgi: unrecognized service
/etc/flask-uwsgi/flask-uwsgi.ini :
[uwsgi]
socket = /var/run/flask-uwsgi/flask-uwsgi.sock
home = /home/ubuntu/canonicaliser_api/venv
wsgi-file = flask_uwsgi.py
callable = app
master = true
; www-data uid/gid
uid = 33
gid = 33
http-socket = :8888
die-on-term = true
processes = 4
threads = 2
logger = file:/var/log/flask-uwsgi/flask-uwsgi.log
/etc/init/flask-uwsgi.conf:
start on [2345]
stop on [06]
script
cd /home/ubuntu/canonicaliser_api
exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini
end script
当ssh进入这个过程时,我可以像这样直接运行uwsgi并且它可以工作:
exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini
所以docker不支持服务,我必须直接在docker镜像中运行它,如下所示:
RUN exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini
或者我错过了什么。
答案 0 :(得分:0)
是的,不要使用服务。
你不能这样做:
RUN exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini
该行将完成,并提交给图像。但是该过程将不再在后续指令中运行,也不会在容器启动时运行。
相反,您可以在ENTRYPOINT或CMD命令中执行此操作,因为它们在容器启动时执行。这应该有效:
CMD uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini
其他一些观点:
RUN rm -rf ...
并不能节省任何空间;这些文件已经提交到上一层。您需要删除添加的相同指令中的文件,以避免在图像中使用空格。USER www-data
而不是chowning文件可能是有意义的。