Docker RUN does NOT persist files
<p>I have a problem with Docker which does not persist commands launch via "RUN".</p>

<p>Here is my Dockerfile :</p>

<pre><code>FROM jenkins:latest

RUN echo "foo" &gt; /var/jenkins_home/toto ; ls -alh  /var/jenkins_home
RUN ls -alh  /var/jenkins_home

RUN rm /var/jenkins_home/.bash_logout  ; ls -alh  /var/jenkins_home
RUN ls -alh  /var/jenkins_home

RUN echo "bar" &gt;&gt; /var/jenkins_home/.profile ; cat /var/jenkins_home/.profile
RUN  cat /var/jenkins_home/.profile
</code></pre>

<p>And here is the output :</p>

<pre><code>Sending build context to Docker daemon 373.8 kB Step 1 : FROM jenkins:latest  ---&gt; fc39417bd5fb Step 2 : RUN echo "foo" &gt; /var/jenkins_home/toto ; ls -alh  /var/jenkins_home  ---&gt; Using cache 
---&gt; c614b13d9d83 Step 3 : RUN ls -alh  /var/jenkins_home  ---&gt; Using cache  ---&gt; 8a16a0c92f67 Step 4 : RUN rm /var/jenkins_home/.bash_logout  ; ls -alh  /var/jenkins_home  ---&gt; Using cache  ---&gt; f6ca5d5bdc64 Step 5 : RUN ls -alh  /var/jenkins_home
---&gt; Using cache  ---&gt; 3372c3275b1b Step 6 : RUN echo "bar" &gt;&gt; /var/jenkins_home/.profile ; cat /var/jenkins_home/.profile  ---&gt; Running in 79842be2c6e3
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then     . "$HOME/.bashrc"
    fi fi

# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH" fi bar  ---&gt; 28559b8fe041 Removing intermediate container 79842be2c6e3 Step 7 : RUN cat /var/jenkins_home/.profile  ---&gt; Running in c694e0cb5866
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then     . "$HOME/.bashrc"
    fi fi

# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH" fi  ---&gt; b7e47d65d65e Removing intermediate container c694e0cb5866 Successfully built b7e47d65d65e
</code></pre>

<p>Do you guys know why "foo" file is not persisted on step 3? Why ".bash_logout" file is recreated on step 5? Why "bar" is not in my ".profile" file anymore on step 7?</p>

<p>And of course, if I start a container based on this image, none of my modifications are persisted... so my Dockerfile is... useless. Any clue?</p>