conv3d
conv3d

Reputation: 2896

Where to place nginx.conf file in docker container

I have a flask app running in AWS ec2 inside a docker container and I am having latency problems. I figured this is because inside the container, localhost routes to both ipv4's 127.0.0.1 and ipv6's ::1 (based on some other SO posts). I found this blog post which addresses the issue exactly. But in the blog he uses nginx, which I've never used before. He has an nginx config file:

location / { try_files $uri @project; }
location @project {
    include uwsgi_params;
    uwsgi_pass unix:/tmp/uwsgi.sock;
}

and I'm not sure how I can place this in the container so that it reads properly. I read somewhere that it goes in /etc/nginx, but then how do I edit the dockerfile to include this conf there?

This is the Dockerfile he suggests. Is the line ADD nginx /etc/nginx where the file is getting copied in? and he just didn't give the file an extension?

FROM ubuntu:14.04

RUN apt-get update && apt-get install -y build-essential nginx python3.4 python3.4-dev
RUN easy_install3 pip

WORKDIR /project

ADD requirements.txt /project/requirements.txt
RUN pip install -r requirements.txt

ADD . /project

ADD nginx /etc/nginx

CMD uwsgi -s /tmp/uwsgi.sock -w project:app --chown-socket=www-data:www-data --enable-threads & \
    nginx -g 'daemon off;'

Upvotes: 4

Views: 22152

Answers (1)

Misantorp
Misantorp

Reputation: 2821

Yes, he is adding the file nginx to the container file system location /etc/nginx/

Personally I'd name the file nginx.conf as that is the default name according to the nginx documentation.

By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.

Also, I'd recommend using COPY in stead of ADD according to the Best practices for writing Dockerfiles

For other items (files, directories) that do not require ADD’s tar auto-extraction capability, you should always use COPY.

To make this work you'll need to install nginx on the container you're running flask on.

Upvotes: 3

Related Questions