@@ -13,18 +13,37 @@ WORKDIR /usr/src/app
1313# Copy from host to image
1414COPY . .
1515
16- # Install flask app dependencies with pip (pip3 also works)
17- RUN pip install -r src/requirements.txt
16+ # Nginx package from EPEL is old, we create a new repository file to install the latest mainline version of Nginx
17+ RUN echo $'[nginx-mainline]\n \
18+ name=nginx mainline repo\n \
19+ baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/\n \
20+ gpgcheck=0\n \
21+ enabled=1\n ' \
22+ >> /etc/yum.repos.d/nginx.repo
23+
24+ # Reduce the number of layers in image by minimizing the number of separate RUN commands
25+ # 1 - Install nginx (using the custom yum repo specified earlier)
26+ # 2 - Remove the default nginx config file
27+ # 3 - Overwrite the nginx.conf with ours to run nginx as non-root
28+ # 4 - Install flask app dependencies with pip (pip3 also works)
29+ # 5 - Make the start script executable
30+ # 6 - Clean all yum cache
31+ RUN yum install -y nginx && \
32+ rm /etc/nginx/conf.d/default.conf && \
33+ mv nginx.conf /etc/nginx/nginx.conf && \
34+ pip install -r src/requirements.txt && \
35+ chmod +x start.sh && \
36+ yum clean all
1837
1938# The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
2039# EXPOSE does not make the ports of the container accessible to the host.
21- EXPOSE 5000
40+ # Here 5000 is for the uwsgi socket, 8080 for nginx
41+ EXPOSE 5000 8080
2242
2343# Set an entrypoint
2444COPY entrypoint.sh /usr/local/bin/entrypoint.sh
2545RUN chmod +x /usr/local/bin/entrypoint.sh
2646
2747ENTRYPOINT ["/usr/local/bin/entrypoint.sh" ]
2848
29- # Finally, we run uWSGI with the ini file
30- CMD [ "uwsgi" , "--ini" , "/usr/src/app/src/uwsgi.ini" ]
49+ CMD ["./start.sh" ]
0 commit comments