title: Dockerfile COPY not overwriting Nginx configuration (or Nginx overwrites on container start) - why?
body: <p>I have a Dockerfile I use for containerizing Python Flask-based microservices that's based on this base Docker image: <a href="https://github.com/tiangolo/uwsgi-nginx-flask-docker" rel="nofollow noreferrer">https://github.com/tiangolo/uwsgi-nginx-flask-docker</a></p>
  
  <p>In my Dockerfile, I add a custom <code>nginx.conf</code> and overwrite Nginx's:</p>
  
  <pre><code>FROM tiangolo/uwsgi-nginx-flask:python3.6
  
  ADD nginx.conf nginx.conf
  
  COPY ./app /app
  COPY ./data /app/data
  COPY nginx.conf /etc/nginx/conf.d/
  </code></pre>
  
  <p>My custom <code>nginx.conf</code> includes only one change - a single <code>server_name</code> that I prepare with a custom domain name:</p>
  
  <pre><code>server {
      listen 80;
      location / {
          try_files $uri @app;
      }
      location @app {
          include uwsgi_params;
          uwsgi_pass unix:///tmp/uwsgi.sock;
      }
      location /static {
          alias /app/static;
      }
      server_name my-fully-qualified-domain-name.com;
  }
  </code></pre>
  
  <p>The reason for this is that I want to run Let's Encrypt's <code>certbot</code> utility to force Nginx to be SSL-only within the container.</p>
  
  <p><strong>The problem:</strong> Docker refuses to overwrite <code>nginx.conf</code>. It pretty much refuses to put anything I try into <code>/etc/nginx/conf.d/</code>.</p>
  
  <p>Or maybe Docker <em>does</em> overwrite it, but something within Nginx on start (at container start) overwrites <em>my</em> changes. I haven't figured it out, but I'd really like to clobber that <code>nginx.conf</code> with my own changes.</p>
  
  <p>Even attaching to the container and manually overwriting Nginx's configuration - then committing those changes to the container using <code>docker commit</code> fails. I suspect there's just something I'm not understanding about how Docker's <code>COPY</code> command works or how <code>docker commit</code> works - any thoughts/suggestions?</p>
  
  <p><strong>Note #1</strong> - I have not been able to get a custom <code>server_name</code> field working with <code>certbot</code> using separate Nginx configuration files (per <a href="https://github.com/tiangolo/uwsgi-nginx-flask-docker#customizing-nginx-configurations" rel="nofollow noreferrer">these instructions</a>). The only way I've been able to get <code>certbot</code> to pick up the right <code>server_name</code> has been by clobbering &amp; overwriting the default <code>nginx.conf</code>, hence going this approach. Perhaps I'm simply using custom Nginx configuration files incorrectly - any suggestions on that note would be greatly appreciated - but I had gone down that road before and was not successful.</p>
  
  <p><strong>Note #2</strong> - I am able to run <code>certbot</code> on a <em>running</em> container (after attaching &amp; overwriting Nginx's configuration), and that works great - SSL on my container, awesome - until the container stops and restarts. Then it's all wiped away and I need to overwrite Nginx's configuration &amp; run <code>certbot</code> again - not ideal at all.</p>