Docker: uwsgi service not recognized

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

      

When I try to run this docker, I get the error:

flask-uwsgi: unrecognized service

      

So I ended up unrolling the last two lines so that nginx starts up and maintains the docker process. Then I went to it for debugging.

docker exec -it 20b2ff3a4cac bash

      

Now when I try to start the service it is the same problem and I cannot find any missing step. Maybe services are not allowed to run in 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

      

While ssh'ed into the process, I can start uwsgi like this directly and it works:

exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini

      

So services are not supported in docker and I have to run them directly in dockerfile like this:

RUN exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini

      

Or am I missing something.

+3


source to share


1 answer


Yes, don't use the services.

You cannot do this though:

RUN exec uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini

      

This line will be completed and anchored to the image. But this process will no longer work in subsequent instructions or when starting the container.



Instead, you can do it in the ENTRYPOINT or CMD command, since they are executed when the container starts. This should work:

CMD uwsgi --ini /etc/flask-uwsgi/flask-uwsgi.ini

      

Some other points:

  • it may be easier for you if you are using one of the official python images .
  • I would just get rid of virtualenv; I don't see the benefit of virtualenv in an isolated container.
  • Launch RUN rm -rf ...

    does not preserve space; these files have already been linked to the previous layer. You need to delete the files in the same instructions they added to avoid wasting space in the image.
  • It might make sense to do USER www-data

    , not chowning files.
0


source







All Articles