Unable to change nginx.conf in the image
See original GitHub issueThis 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:
- Created 6 years ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
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
proxyservice in the Docker Compose file and the Traefik labels in each service connected to it.@VimanyuAgg please, check the docs: https://github.com/tiangolo/uwsgi-nginx-flask-docker#customizing-nginx-configurations
The files
nginx.confandupload.confare 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?