Unable to change nginx.conf file Unable to change nginx.conf file nginx nginx

Unable to change nginx.conf file


As it turns out, the parent image has already added a specific file into the image, which is read-only. This means you sadly can't change or overwrite the file.

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 change the file there, which is in another namespace and different permissions (afaik). It worked on my end.

docker create -v /usr/local/share/nginxconf:/etc/nginx/conf.d --name flask-test IMAGE_NAMEvim /usr/local/share/nginxconf/nginx.conf

Another, fancier solution would be to take another parent image, which doesn't add the file beforehand. But I don't know what dependencies you need for your app, so it might be a painful search. You could of course also create your own (which would also give you some training in writing Dockerfiles).

References to writing a successful Dockerfile:

Dockerfile Reference

Dockerfile Best Practices

Handy tutorial to dockerize PostreSQL by Docker


I suggest you to put your config file in a volume, so you can edit the file on the host and it will be changed inside the container as well.

To do that, you can run your container with

docker run -d -v /path/to/changes/nginx.conf:/etc/nginx/conf.d/nginx.conf IMAGE_NAME

After a change of the config, don't forget to test and apply the config with

docker exec -ti CONTAINER_NAME /bin/sh -c "nginx -t && nginx -s reload"

Also I advise you against installing vim inside the image, as images are supposed to be lightweight and unnecessary packages should abstain from being installed


At the moment I use the same image for deploy apps with django.This image has a script that execute when the container is starting.

The solution for me works it was created a new file with my custom configuration nginx.conf then modify script prestart.sh add new line for copy and replace default file in /etc/conf.d/nginx.conf

create new custom file /mypath/file_Custom_nginx.conf

then add new line in script prestart.sh

cp /mypath/file_Custom_nginx.conf /etc/conf.d/nginx.conf

restart the container.

now for each reboot the script replace the file configuration nginx.

Note: I use supervisord for management services nginx

I hoppe it help you