Files in docker container disappear

2.1k views Asked by At

I am working on creating a backup script for some Docker contains. Some really strange thing happens when I copy files from a dir inside a Docker container to a host mounted dir - The files disappear.

EDIT: I managed to simplify the example and isolate the strange phenomenon:

#!/usr/bin/env bash

docker run -it --name  gen_skeleton_cont \
        mailman_server \
        ls /etc && \
        echo "Second ls:" && \
        ls /etc \    

# Cleanup the gen_skeleton_cont:
docker rm -f gen_skeleton_cont

The output of running this script is:

$ sudo bash check_incon.sh 
Muttrc        bash.bashrc             cron.monthly    environment  hosts.allow      issue.net      logcheck        mke2fs.conf    os-release  python     rc6.d         services  sudoers      ufw
Muttrc.d      bash_completion.d       cron.weekly     fstab        hosts.deny       kbd            login.defs      modprobe.d     pam.conf    python2.7  rcS.d         sgml      sudoers.d    update-motd.d
X11           bindresvport.blacklist  crontab         fstab.d      init             kernel         logrotate.conf  modules        pam.d       python3    resolv.conf   shadow    supervisor   upstart-xsessions
adduser.conf  blkid.conf              dbus-1          gai.conf     init.d           ld.so.cache    logrotate.d     mtab           passwd      python3.4  resolvconf    shadow-   sysctl.conf  vim
aliases       blkid.tab               debconf.conf    group        initramfs-tools  ld.so.conf     lsb-release     network        passwd-     rc.local   rmt           shells    sysctl.d     vtrgb
aliases.db    ca-certificates         debian_version  group-       inputrc          ld.so.conf.d   magic           networks       perl        rc0.d      rpc           skel      syslog-ng    wgetrc
alternatives  ca-certificates.conf    default         gshadow      insserv          ldap           magic.mime      newt           postfix     rc1.d      rsyslog.conf  ssl       systemd      xml
apache2       console-setup           deluser.conf    gshadow-     insserv.conf     legal          mailcap         nologin        ppp         rc2.d      rsyslog.d     subgid    terminfo
apparmor      cron.d                  depmod.d        host.conf    insserv.conf.d   libaudit.conf  mailcap.order   nsswitch.conf  profile     rc3.d      securetty     subgid-   timezone
apparmor.d    cron.daily              dhcp            hostname     iproute2         locale.alias   mailman         ntp.conf       profile.d   rc4.d      security      subuid    ucf.conf
apt           cron.hourly             dpkg            hosts        issue            localtime      mime.types      opt            protocols   rc5.d      selinux       subuid-   udev
Second ls:
acpi                    ca-certificates.conf  dhcp          host.conf        kbd              lsb-release     opt                      python3.4        screenrc   sudoers            w3m
adduser.conf            calendar              digitalocean  hostname         kernel           ltrace.conf     os-release               rc0.d            securetty  sudoers.d          wgetrc
alternatives            chatscripts           dpkg          hosts            kernel-img.conf  magic           pam.conf                 rc1.d            security   sysctl.conf        wireshark
apm                     cloud                 environment   hosts.allow      landscape        magic.mime      pam.d                    rc2.d            selinux    sysctl.d           wpa_supplicant
apparmor                console-setup         fish          hosts.deny       ldap             mailcap         passwd                   rc3.d            services   systemd            X11
apparmor.d              cron.d                fonts         ifplugd          ld.so.cache      mailcap.order   passwd-                  rc4.d            sgml       terminfo           xml
apport                  cron.daily            fstab         init             ld.so.conf       manpath.config  perl                     rc5.d            shadow     timezone           zsh_command_not_found
apt                     cron.hourly           fstab.d       init.d           ld.so.conf.d     mime.types      pm                       rc6.d            shadow-    ucf.conf
at.deny                 cron.monthly          fuse.conf     initramfs-tools  legal            mke2fs.conf     polkit-1                 rc.digitalocean  shells     udev
bash.bashrc             crontab               gai.conf      inputrc          libaudit.conf    modprobe.d      popularity-contest.conf  rc.local         skel       ufw
bash_completion         cron.weekly           groff         insserv          libnl-3          modules         ppp                      rcS.d            smi.conf   updatedb.conf
bash_completion.d       dbus-1                group         insserv.conf     locale.alias     mtab            profile                  resolvconf       ssh        update-manager
bindresvport.blacklist  debconf.conf          group-        insserv.conf.d   localtime        nanorc          profile.d                resolv.conf      ssl        update-motd.d
blkid.conf              debian_version        grub.d        iproute2         logcheck         network         protocols                rmt              subgid     update-notifier
blkid.tab               default               gshadow       iscsi            login.defs       networks        python                   rpc              subgid-    upstart-xsessions
byobu                   deluser.conf          gshadow-      issue            logrotate.conf   newt            python2.7                rsyslog.conf     subuid     vim
ca-certificates         depmod.d              hdparm.conf   issue.net        logrotate.d      nsswitch.conf   python3                  rsyslog.d        subuid-    vtrgb
gen_skeleton_cont

As can be seen, the two invocations of ls give different results. Maybe the container hasn't finished loading? I must be missing something.

If it helps, the full repository is here (Including Docker files): https://github.com/realcr/mailman_docker

1

There are 1 answers

0
real On BEST ANSWER

I think I found the problem. It is not related to Docker at all. It's a bash thing.

When invoking:

docker run -it --name  gen_skeleton_cont \
        mailman_server \
        ls /etc && \
        echo "Second ls:" && \
        ls /etc \    

The first ls happens inside the Docker container, however the second one happens inside the host machine. I should find some other way to run multiple commands inside a Docker container, maybe using another .sh file.