title: Why "RUN rm /etc/nginx/conf.d/default.conf" did not succeed?
body: <p>I don't want my nginx docker image to have <code>/etc/nginx/conf.d/default.conf</code> so I wrote a simple nginx dockerfile, mainly to add <code>RUN rm /etc/nginx/conf.d/default.conf</code></p>
  
  <p>To my surprise it did not work. /etc/nginx/conf.d/default.conf is still there.</p>
  
  <p>Why and how do I delete it ?</p>
  
  <p>My dockerfile:</p>
  
  <pre><code>FROM nginx:latest
  
  # Copy custom configuration file from the current directory
  RUN rm /etc/nginx/conf.d/default.conf
  COPY nginx.conf /etc/nginx/nginx.conf
  COPY conf.d/node2 /etc/nginx/conf.d/node2
  EXPOSE 80 8080
  </code></pre>
  
  <p>My docker-compose.yml for nginx service adds a name volumn</p>
  
  <pre><code>volumes:
  - conf:/etc/nginx/conf.d
  </code></pre>
  
  <p>Update:</p>
  
  <p>I finally found out that it is because I created a name volume in my docker-compose.yml that create <code>/etc/nginx/conf.d/default.conf</code> so rm in dockerfile won't work at all. But why creating a name volume will result in creating `/etc/nginx/conf.d/default.conf ?</p>
  
  <p>Update2:</p>
  
  <p>With the second answer I got I finally figure out why. So <code>RUN rm /etc/nginx/conf.d/default.conf</code> did work. The problem is I used a volume in my docker-compose.yml that was created before I run <code>RUN rm /etc/nginx/conf.d/default.conf</code> and that volume has default.conf. </p>
  
  <p>It happened like this, I first used a dockerfile without rm and run <code>docker-compose up</code>, then I added rm to it to rebuild the image and run <code>docker-compose up</code> again. But I never change my docker-compose.yml or clean my volume. So the file was there no matter how I build/rebuild my image. </p>
  
  <p>After I deleted all the old volume (using <em>docker volume rm <code>docker volume ls -q -f dangling=true</code></em>) it finally works.</p>
  
  <p>I leave my question here instead of deleting it just in case someone else may make the same mistake like I did :$</p>