Removing a file from a docker container

It’s quite simple but I don’t have any explanation why this is not working:

In my Dockerfile:

  • Use Maven and Docker + Nexus 3 behind NGinx with HTTPS
  • Laradock + Webpack + Hot-reload
  • Docker container blocking text/event-stream
  • Replacing a particular instance on AWS Elastic BeanStalk?
  • Docker-based Ambari 1.7 cluster install wizard repo URL dead (404) while 'Running setup agent script'
  • docker push has integrity failures from a given commit and onwards
  • RUN rm -rf /etc/nginx/sites-*/*
    

    Once built and run, inside the container the files are still there:

    ls -lrth /etc/nginx/sites-*/*
    -rw-r--r-- 1 root root 2.1K Jan 26 23:34 /etc/nginx/sites-available/default
    lrwxrwxrwx 1 root root   34 Apr 21 15:58 /etc/nginx/sites-enabled/default -> /etc/nginx/sites-available/default
    -rw-r--r-- 1 root root  691 Apr 21 16:12 /etc/nginx/sites-available/default.conf
    lrwxrwxrwx 1 root root   39 Apr 21 16:17 /etc/nginx/sites-enabled/default.conf -> /etc/nginx/sites-available/default.conf
    

    I can see in th build that the action was done:

    Step 13 : RUN rm -rf /etc/nginx/sites-*/*
     ---> Running in 0fa2deabe45c
     ---> 33e7b85a6c05
    

    This is my Dockerfile:

    FROM ubuntu:14.04.4
    
    ENV DEBIAN_FRONTEND noninteractive
    
    RUN apt-get update
    RUN apt-get install -y software-properties-common
    RUN add-apt-repository ppa:nginx/stable
    RUN add-apt-repository ppa:ondrej/php
    
    RUN add-apt-repository ppa:ondrej/php
    
    RUN apt-get update
    RUN apt-get upgrade -y
    RUN apt-get -y --force-yes install php7.0-fpm git php7.0-mysql php7.0-curl
    
    RUN apt-get install --force-yes -y nginx
    
    RUN rm -rf /etc/nginx/sites-*/*
    

  • Docker: can't run hello-world. Windows 10
  • How to access to a file in docker container already exit?
  • Running atop in a docker stack
  • Public IP mapping to internal shared virtual ip address in Docker
  • Ruby docker-api to mount volume
  • Docker: npm install behind proxy
  • One Solution collect form web for “Removing a file from a docker container”

    This seems to work for me as expected.

    I started by putting setting up your Dockerfile locally:

    $ mkdir dockertest
    $ cd dockertest
    $ cat > Dockerfile
    <paste dockerfile here>
    

    Then building the image:

    $ docker build -t dockertest .
    

    You can see the complete build process here.

    Once the image is built, I can verify that those directories are empty:

    bash-4.3$ docker run --rm dockertest ls -l /etc/nginx/sites-{available,enabled}/
    /etc/nginx/sites-available/:
    total 0
    
    /etc/nginx/sites-enabled/:
    total 0
    bash-4.3$ 
    

    You’ll note that I didn’t use wildcards in the previous command. If I had instead run this…

    $ docker run --rm dockertest ls -l /etc/nginx/sites-*/*
    

    …that would have listed files on my host filesystem, because shell wildcard expansion happens before the command runs. You could do this safely by running:

    $ docker run --rm dockertest sh -c 'ls -l /etc/nginx/sites-*/*'
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.