David Foie Gras
David Foie Gras

Reputation: 2080

uwsgi-nginx in docker not works

I have Dockerfile like:

FROM python:3.6.5-jessie
MAINTAINER twitter myname

RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y nginx
RUN pip install --upgrade pip

RUN git clone https://github.com/hongmingu/requirements
RUN pip install -r /requirements/requirements_django.txt
RUN apt-get install -y vim

RUN mkdir -p /uwsgi_log

RUN git clone https://github.com/hongmingu/smaple_django

RUN apt-get install -y nginx

COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./uwsgi.ini /uwsgi.ini # it runs in daemonized mode
# These files are just setting files. nginx get request at port 8000 and uwsgi runs django project.

RUN uwsgi --ini /uwsgi.ini

RUN service nginx restart

CMD ["python3"]

I think these 2 lines not work:

RUN uwsgi --ini /uwsgi.ini
RUN service nginx restart

Because When I build it and run it with linux command: sudo docker run --rm -it -p 8080:8000 hongmingu/smaple:0.1 /bin/bash my 127.0.0.1:8080 does not work. But, When I attach container and type command manually like, uwsgi --ini /uwsgi.ini and service nginx restart, It works well.

So, Is it impossible to run uwsgi, nginx in Dockerfile?

I want to do it so that I hope I don't need to run uwsgi and nginx manually.

Where did I make fault? Is there any good way to do this?

This docker image(hongmingu/smaple:0.1) is here: https://cloud.docker.com/u/hongmingu/repository/docker/hongmingu/smaple

Upvotes: 0

Views: 406

Answers (1)

Siyu
Siyu

Reputation: 12089

You misunderstood the RUN instruction

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results

It's used to build your image, it is not docker run which executes the command in the container.

The solutions involves to execute those 2 lines in the CMD or ENTRYPOINT with a shell script. uwsgi has also to be daemonized. Checkout this image https://github.com/tiangolo/uwsgi-nginx-docker

Upvotes: 1

Related Questions