docker容器中的文件消失

时间:2014-11-22 13:37:28

标签: bash docker mailman

我正在为一些Docker包含创建备份脚本。当我将文件从Docker容器中的目录复制到主机安装的目录时,会发生一些非常奇怪的事情 - 文件消失。

编辑:我设法简化了示例并隔离了这个奇怪的现象:

#!/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

运行此脚本的输出是:

$ 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

可以看出,ls的两次调用给出了不同的结果。也许容器没有装完?我一定错过了什么。

如果有帮助,那么完整的存储库就在这里(包括Docker文件): https://github.com/realcr/mailman_docker

1 个答案:

答案 0 :(得分:1)

我想我发现了这个问题。它根本与Docker无关。这是一件大事。

调用时:

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

第一个ls发生在Docker容器内,但第二个发生在主机内部。我应该找到一些在Docker容器中运行多个命令的方法,可能使用另一个.sh文件。