Edit and apply configuration change in nginx server using helper container

Hi,
I am trying to create 2 container.

  1. First Container (mynginx) will have Nginx server running on 8080 port and have few data volumes like nginx/conf/nginx.conf
  2. Second container (nginxconf) is my helper container to edit nginx.conf file by accessing the volumes(nginx/conf/nginx.conf) using --volumes-from option.
    I am able to edit the nginx.conf file and successfully change the port from 8080 to 8085. But now facing below problems-:
  3. Restarting service in mynginx container will run service on 8085 but how this port will be mapped to host public port. As currently docker ps is howing 8080 port is mapped to 32768 and after service restart , it is not changing at all and i am not able to access nginx from host system.
  4. If i am trying to save the container state into image as i have change the port from 8080 to 8085, docker commit is not saving this port change into new image as nginx/conf/nginx.conf is a volume where commit might not working.

Please advise how to use helper container for editing configuration in actual container or i am going on wrong way at all.

Note-: I have referred this topic on docker blog.

Thanks
Amandeep.

Is your goal just to change the port nginx is running on? You should stop your current nginx container (on the host) and start a new one with a new -p mapping. Importantly, the port number inside the container doesn’t matter at all. So if before you were running

docker run -d -p 8080:8080 --name mynginx me/nginx

without changing anything in the nginx config at all, you can run

docker stop mynginx
docker rm mynginx
docker run -d -p 8085:8080 --name mynginx me/nginx

In my experience you generally don’t try to stop and restart daemons within running containers; it’s easier (and pretty cheap) to just restart the whole container.