question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to change nginx.conf in the image

See original GitHub issue

This may seem a little strange, but I am not able to change nginx.conf file inside /etc/nginx/conf.d/nginx.conf

Here is what I did:

Method1: Change in Dockerfile

My Dockerfile looks like this:

FROM tiangolo/uwsgi-nginx-flask:flask
COPY ./app /app
COPY ./changes/nginx.conf /etc/nginx/conf.d/nginx.conf
COPY ./changes/nginx.conf /app/

./changes/nginx.conf looks like this:

server {
    location /app1/ {
        try_files $uri @app;
    }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }
    location /static {
        alias /app/static;
    }
}

Note the change in location in above server block from location / to location /app1/

After the image is built and I run the docker container, I exec into the running container sudo docker exec -ti CONTAINER_ID /bin/bash

cat /app/nginx.conf shows presence of updated nginx.conf file (location changes from / to /app1/

BUT cat /etc/nginx/conf.d/nginx.conf still shows the old conf file (location is still /) I thought maybe the second COPY line is not getting executed successfully and docker isn’t throwing error on console (sudo?). So, I changed the conf file manually and did a docker commit - the second approach mentioned below.

Method2: Docker commit

After the docker container was up and running, I used exec to login into the container using [vagrant@localhost]$ sudo docker exec -ti CONTAINER_ID /bin/bash

[root@CONTAINER_ID]# vi /etc/nginx/conf.d/nginx.conf Changing the file to reflect below:

server {
    location /app1/ {
        try_files $uri @app;
    }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }
    location /static {
        alias /app/static;
    }
}

Saved the file wq! and exit the container. After that I did sudo docker commit CONTAINER_ID my_new_image

Starting a new container and re-logging into container running on my_new_image still gives below nginx.conf file inside /etc/nginx/conf.d/nginx.conf:

server {
    location / {
        try_files $uri @app;
    }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }
    location /static {
        alias /app/static;
    }
}

I can tell that the my_new_image has some changes because it is larger in size than tiangolo/uwsgi-nginx-flask-docker because I had installed vim to edit the file. But somehow file changes are not persisting inside /etc/nginx/conf.d/nginx.conf.

Am I doing something wrong or is it some bug?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tiangolocommented, Dec 10, 2017

Oh, ok, you really need Traefik.

Check this project generator (it uses this image). It includes Flask as back end, another container as front end, both in the same domain but different URL (that achieves the same that you need).

It also contains a Celery worker, Postgres, SQLAlchemy and other stuff. But just check the proxy service in the Docker Compose file and the Traefik labels in each service connected to it.

1reaction
tiangolocommented, Nov 2, 2017

@VimanyuAgg please, check the docs: https://github.com/tiangolo/uwsgi-nginx-flask-docker#customizing-nginx-configurations

The files nginx.conf and upload.conf are created by the image based on environment variables.

If you need to add additional Nginx configurations, add them with a different name, for example, custom.conf. Otherwise, they will be overwritten.


Now, apart from modifying the Nginx configs, what are you exactly trying to achieve? Why do you think you need to modify the Nginx configurations?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to change nginx.conf file - docker - Stack Overflow
A hacky solution to this is to mount the /etc/nginx/conf.d folder into a directory on your host (let's say /usr/local/share/nginxconf ) and ...
Read more >
Docker NGINX issue -- unable to edit nginx.conf
This way you can easily change the file outside the container and then just restart the container.
Read more >
How to Deploy an NGINX Image with Docker
Option 1 – Maintain the Content and Configuration on the Docker Host ... Now any change made to the files in the local...
Read more >
I installed nginx on ubuntu, can not edit the configuration files ...
In Ubuntu and Debian based system, we need to modify the /etc/nginx/sites-enabled/default file and on RHEL and CentOS based distributions edit /etc/nginx/nginx.
Read more >
NGINX settings - GitLab Docs
Configuring the PROXY protocol · Edit /etc/gitlab/gitlab.rb : # Enable termination of ProxyProtocol by NGINX nginx['proxy_protocol'] = true # Configure trusted ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found