首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Debian主机: CTRL +P+Q不能使容器存活

Debian主机: CTRL +P+Q不能使容器存活
EN

Stack Overflow用户
提问于 2016-02-11 11:20:43
回答 1查看 308关注 0票数 0

我正在跟踪Docker网站上的自定节奏视频教程:https://training.docker.com/self-paced-training

在第一段视频中,导师讨论了拆船坞的问题,同时还保留了集装箱的生命。显示的示例是运行:

代码语言:javascript
复制
docker run -i -d ubuntu:latest  /bin/bash

然后,在创建容器时,用以下方式退出:

代码语言:javascript
复制
CTRL + P + Q

这似乎不适合我。我注意到导师在用Windows和Putty。我在我的Debian开发机器上使用了docker,所以我不确定用于分离的命令是否不同。

当我按下上面的键组合时,它从容器中退出,但正在运行:

代码语言:javascript
复制
ps -ef

..。没有显示任何容器。这是我的输出:

代码语言:javascript
复制
sheldon@yosec:~$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Feb10 ?        00:00:03 /sbin/init
root         2     0  0 Feb10 ?        00:00:00 [kthreadd]
root         3     2  0 Feb10 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 Feb10 ?        00:00:00 [kworker/0:0H]
root         7     2  0 Feb10 ?        00:00:04 [rcu_sched]
root         8     2  0 Feb10 ?        00:00:00 [rcu_bh]
root         9     2  0 Feb10 ?        00:00:00 [migration/0]
root        10     2  0 Feb10 ?        00:00:00 [watchdog/0]
root        11     2  0 Feb10 ?        00:00:00 [watchdog/1]
root        12     2  0 Feb10 ?        00:00:00 [migration/1]
root        13     2  0 Feb10 ?        00:00:00 [ksoftirqd/1]
root        15     2  0 Feb10 ?        00:00:00 [kworker/1:0H]
root        16     2  0 Feb10 ?        00:00:00 [watchdog/2]
root        17     2  0 Feb10 ?        00:00:00 [migration/2]
root        18     2  0 Feb10 ?        00:00:00 [ksoftirqd/2]
root        20     2  0 Feb10 ?        00:00:00 [kworker/2:0H]
root        21     2  0 Feb10 ?        00:00:00 [watchdog/3]
root        22     2  0 Feb10 ?        00:00:00 [migration/3]
root        23     2  0 Feb10 ?        00:00:00 [ksoftirqd/3]
root        25     2  0 Feb10 ?        00:00:00 [kworker/3:0H]
root        26     2  0 Feb10 ?        00:00:00 [khelper]
root        27     2  0 Feb10 ?        00:00:00 [kdevtmpfs]
root        28     2  0 Feb10 ?        00:00:00 [netns]
root        29     2  0 Feb10 ?        00:00:00 [khungtaskd]
root        30     2  0 Feb10 ?        00:00:00 [writeback]
root        31     2  0 Feb10 ?        00:00:00 [ksmd]
root        32     2  0 Feb10 ?        00:00:00 [khugepaged]
root        33     2  0 Feb10 ?        00:00:00 [crypto]
root        34     2  0 Feb10 ?        00:00:00 [kintegrityd]
root        35     2  0 Feb10 ?        00:00:00 [bioset]
root        36     2  0 Feb10 ?        00:00:00 [kblockd]
root        39     2  0 Feb10 ?        00:00:00 [kswapd0]
root        40     2  0 Feb10 ?        00:00:00 [fsnotify_mark]
root        46     2  0 Feb10 ?        00:00:00 [kthrotld]
root        47     2  0 Feb10 ?        00:00:00 [ipv6_addrconf]
root        49     2  0 Feb10 ?        00:00:00 [deferwq]
root        93     2  0 Feb10 ?        00:00:00 [khubd]
root        94     2  0 Feb10 ?        00:00:00 [ata_sff]
root       106     2  0 Feb10 ?        00:00:00 [scsi_eh_0]
root       107     2  0 Feb10 ?        00:00:00 [scsi_tmf_0]
root       108     2  0 Feb10 ?        00:00:00 [scsi_eh_1]
root       109     2  0 Feb10 ?        00:00:00 [scsi_tmf_1]
root       134     2  0 Feb10 ?        00:00:01 [kworker/2:1H]
root       136     2  0 Feb10 ?        00:00:01 [kworker/0:1H]
root       137     2  0 Feb10 ?        00:00:00 [kworker/3:1H]
root       172     2  0 Feb10 ?        00:00:00 [kdmflush]
root       174     2  0 Feb10 ?        00:00:00 [bioset]
root       175     2  0 Feb10 ?        00:00:00 [kcryptd_io]
root       176     2  0 Feb10 ?        00:00:00 [kcryptd]
root       178     2  0 Feb10 ?        00:00:00 [bioset]
root       180     2  0 Feb10 ?        00:00:00 [kworker/1:1H]
root       185     2  0 Feb10 ?        00:00:00 [kdmflush]
root       186     2  0 Feb10 ?        00:00:00 [bioset]
root       188     2  0 Feb10 ?        00:00:00 [kdmflush]
root       189     2  0 Feb10 ?        00:00:00 [bioset]
root       191     2  0 Feb10 ?        00:00:00 [kdmflush]
root       193     2  0 Feb10 ?        00:00:00 [bioset]
root       221     2  0 Feb10 ?        00:00:04 [jbd2/dm-1-8]
root       222     2  0 Feb10 ?        00:00:00 [ext4-rsv-conver]
root       253     2  0 Feb10 ?        00:00:00 [kauditd]
root       262     1  0 Feb10 ?        00:00:00 /lib/systemd/systemd-udevd
root       269     1  0 Feb10 ?        00:00:00 /lib/systemd/systemd-journald
root       315     2  0 Feb10 ?        00:00:00 [hd-audio1]
root       322     2  0 Feb10 ?        00:00:00 [kpsmoused]
root       323     2  0 Feb10 ?        00:00:00 [cfg80211]
root       327     2  0 Feb10 ?        00:00:00 [kmemstick]
root       328     2  0 Feb10 ?        00:00:00 [rtsx_usb_ms_2]
root       362     2  0 Feb10 ?        00:00:00 [hd-audio0]
root       401     2  0 Feb10 ?        00:00:00 [ext4-rsv-conver]
root       414     2  0 Feb10 ?        00:00:00 [jbd2/dm-3-8]
root       415     2  0 Feb10 ?        00:00:00 [ext4-rsv-conver]
root       419     2  0 Feb10 ?        00:00:00 [ext4lazyinit]
root       581     1  0 Feb10 ?        00:00:00 /sbin/rpcbind -w
statd      595     1  0 Feb10 ?        00:00:00 /sbin/rpc.statd
root       600     2  0 Feb10 ?        00:00:00 [rpciod]
root       602     2  0 Feb10 ?        00:00:00 [nfsiod]
root       609     1  0 Feb10 ?        00:00:00 /usr/sbin/rpc.idmapd
root       610     1  0 Feb10 ?        00:00:00 /usr/lib/bluetooth/bluetoothd
root       611     1  0 Feb10 ?        00:00:00 /usr/sbin/cron -f
daemon     612     1  0 Feb10 ?        00:00:00 /usr/sbin/atd -f
root       615     1  0 Feb10 ?        00:00:00 /lib/systemd/systemd-logind
message+   617     1  0 Feb10 ?        00:00:12 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd
root       623     1  0 Feb10 ?        00:00:00 /usr/sbin/rsyslogd -n
root       627     1  0 Feb10 ?        00:00:01 /usr/sbin/acpid
root       663     1  0 Feb10 tty1     00:00:00 /bin/login --        
Debian-+   880     1  0 Feb10 ?        00:00:00 /usr/sbin/exim4 -bd -q30m
root       896     1  0 Feb10 ?        00:00:00 dhclient -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases e
sheldon    919   663  0 Feb10 tty1     00:00:00 -bash
root       938   919  0 Feb10 tty1     00:00:00 su root
root       939   938  0 Feb10 tty1     00:00:00 bash
root      1327     1  0 Feb10 ?        00:00:16 /usr/lib/packagekit/packagekitd
root      7497     1  0 Feb10 ?        00:00:00 /usr/lib/upower/upowerd
root      7528     1  0 Feb10 ?        00:00:01 /usr/lib/udisks2/udisksd --no-debug
colord    7568     1  0 Feb10 ?        00:00:00 /usr/lib/colord/colord
root      7608     1  0 Feb10 ?        00:00:00 /usr/lib/accountsservice/accounts-daemon
root      7615     1  0 Feb10 ?        00:00:00 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
root     15042     2  0 09:13 ?        00:00:00 [irq/62-mei_me]
root     15045     2  0 09:13 ?        00:00:00 [kworker/u17:0]
root     15046     2  0 09:13 ?        00:00:00 [hci0]
root     15047     2  0 09:13 ?        00:00:00 [hci0]
root     15055     2  0 09:13 ?        00:00:00 [kworker/u17:2]
root     16443     2  0 10:16 ?        00:00:00 [kworker/3:0]
root     16508     1  0 10:17 ?        00:00:19 /usr/bin/docker daemon -H fd://
root     16586   939  0 10:18 tty1     00:00:00 su sheldon
sheldon  16587     1  0 10:18 ?        00:00:00 /lib/systemd/systemd --user
sheldon  16588 16587  0 10:18 ?        00:00:00 (sd-pam)  
sheldon  16590 16586  0 10:18 tty1     00:00:00 bash
sheldon  16596 16590  0 10:18 tty1     00:00:00 /bin/sh /usr/bin/startx
sheldon  16618 16596  0 10:18 tty1     00:00:00 xinit /etc/X11/xinit/xinitrc -- /etc/X11/xinit/xserverrc :0 vt1 -auth /tmp/serv
root     16619 16618  6 10:18 tty1     00:03:52 /usr/bin/X -nolisten tcp :0 vt1 -auth /tmp/serverauth.91BAA94QlC
sheldon  16625 16618  0 10:18 tty1     00:00:00 x-session-manager
sheldon  16648 16625  0 10:18 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-session-manager
sheldon  16651     1  0 10:18 tty1     00:00:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
sheldon  16652     1  0 10:18 ?        00:00:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
sheldon  16655     1  0 10:18 ?        00:00:00 /usr/lib/at-spi2-core/at-spi-bus-launcher
sheldon  16659 16655  0 10:18 ?        00:00:00 /usr/bin/dbus-daemon --config-file=/etc/at-spi2/accessibility.conf --nofork --p
sheldon  16662     1  0 10:18 ?        00:00:00 /usr/lib/at-spi2-core/at-spi2-registryd --use-gnome-session
sheldon  16672 16625  0 10:18 tty1     00:00:00 /usr/lib/gnome-settings-daemon/gnome-settings-daemon
sheldon  16679     1  0 10:18 tty1     00:00:00 /usr/bin/gnome-keyring-daemon --start --components=pkcs11
sheldon  16694     1  0 10:18 ?        00:00:15 /usr/bin/pulseaudio --start
rtkit    16695     1  0 10:18 ?        00:00:00 /usr/lib/rtkit/rtkit-daemon
sheldon  16697     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfsd
sheldon  16702     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
sheldon  16716     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
sheldon  16723     1  0 10:18 tty1     00:00:00 /bin/sh /usr/bin/start-pulseaudio-x11
sheldon  16724 16723  0 10:18 tty1     00:00:00 /usr/bin/xprop -root -spy
sheldon  16726     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
sheldon  16729     1  0 10:18 ?        00:00:00 /usr/lib/gnome-online-accounts/goa-daemon
sheldon  16735     1  0 10:18 ?        00:00:00 /usr/lib/telepathy/mission-control-5
sheldon  16738     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
sheldon  16745     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
sheldon  16749     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
sheldon  16753 16625  2 10:18 tty1     00:01:24 /usr/bin/gnome-shell
sheldon  16756     1  0 10:18 ?        00:00:00 /usr/lib/dconf/dconf-service
sheldon  16760     1  0 10:18 tty1     00:00:00 /usr/lib/gnome-settings-daemon/gsd-printer
sheldon  16773     1  0 10:18 ?        00:00:00 /usr/lib/gnome-shell/gnome-shell-calendar-server
sheldon  16777     1  0 10:18 ?        00:00:00 /usr/lib/evolution/evolution-source-registry
sheldon  16790 16625  0 10:18 tty1     00:00:00 zeitgeist-datahub
sheldon  16792 16625  0 10:18 tty1     00:00:00 /usr/lib/tracker/tracker-miner-user-guides
sheldon  16793 16625  0 10:18 tty1     00:00:00 /usr/lib/tracker/tracker-miner-fs
sheldon  16794 16625  0 10:18 tty1     00:00:00 /usr/bin/python /usr/share/system-config-printer/applet.py
sheldon  16799 16625  0 10:18 tty1     00:00:00 /usr/lib/tracker/tracker-miner-apps
sheldon  16800 16625  0 10:18 tty1     00:00:00 /usr/lib/evolution/3.12/evolution-alarm-notify
sheldon  16804     1  0 10:18 ?        00:00:01 /usr/lib/tracker/tracker-store
sheldon  16806 16625  0 10:18 tty1     00:00:00 nm-applet
sheldon  16809     1  0 10:18 ?        00:00:00 /usr/bin/zeitgeist-daemon
sheldon  16811 16625  0 10:18 tty1     00:00:00 /usr/lib/tracker/tracker-extract
sheldon  16838     1  0 10:18 ?        00:00:00 /usr/lib/evolution/evolution-calendar-factory
sheldon  16845     1  0 10:18 ?        00:00:00 /usr/lib/x86_64-linux-gnu/gconf/gconfd-2
sheldon  16864     1  0 10:18 ?        00:00:00 /usr/lib/gvfs/gvfsd-metadata
sheldon  16894     1  0 10:18 ?        00:00:00 /usr/lib/x86_64-linux-gnu/zeitgeist-fts
sheldon  16912 16894  0 10:18 ?        00:00:00 /bin/cat
sheldon  17025     1  0 10:19 ?        00:00:04 /usr/lib/gnome-terminal/gnome-terminal-server
sheldon  17143     1  0 10:19 ?        00:00:00 /usr/lib/dleyna-renderer/dleyna-renderer-service
sheldon  17149 17025  0 10:19 ?        00:00:00 gnome-pty-helper
sheldon  17150 17025  0 10:19 pts/0    00:00:00 bash
sheldon  17158     1  0 10:19 ?        00:00:00 /usr/lib/gvfs/gvfsd-burn --spawner :1.9 /org/gtk/gvfs/exec_spaw/0
sheldon  17581 16753 23 10:33 tty1     00:09:36 iceweasel
root     17777     2  0 10:48 ?        00:00:00 [kworker/1:2]
root     18308     2  0 10:57 ?        00:00:00 [kworker/0:1]
root     18576     2  0 11:00 ?        00:00:00 [kworker/u16:0]
root     18839     2  0 11:02 ?        00:00:00 [kworker/2:0]
root     18904 16508  0 11:02 pts/1    00:00:00 /bin/bash
root     18971     2  0 11:08 ?        00:00:00 [kworker/u16:2]
root     18984     2  0 11:08 ?        00:00:00 [kworker/1:0]
root     19038 16508  0 11:08 pts/2    00:00:00 /bin/bash
root     19065     2  0 11:08 ?        00:00:00 [kworker/3:1]
root     19076     2  0 11:08 ?        00:00:00 [kworker/2:2]
root     19131 16508  0 11:08 pts/3    00:00:00 /bin/bash
root     19184     2  0 11:08 ?        00:00:00 [kworker/0:0]
root     19260 16508  0 11:09 pts/4    00:00:00 /bin/bash
root     19493 16508  0 11:10 pts/5    00:00:00 /bin/bash
root     19590 16508  0 11:10 pts/6    00:00:00 /bin/bash
sheldon  19632 17150  0 11:14 pts/0    00:00:00 ps -ef
root     28362     2  0 Feb10 ?        00:00:00 [xfsalloc]
root     28363     2  0 Feb10 ?        00:00:00 [xfs_mru_cache]
root     28364     2  0 Feb10 ?        00:00:00 [xfslogd]
root     28367     2  0 Feb10 ?        00:00:00 [jfsIO]
root     28368     2  0 Feb10 ?        00:00:00 [jfsCommit]
root     28369     2  0 Feb10 ?        00:00:00 [jfsCommit]
root     28370     2  0 Feb10 ?        00:00:00 [jfsCommit]
root     28371     2  0 Feb10 ?        00:00:00 [jfsCommit]
root     28372     2  0 Feb10 ?        00:00:00 [jfsSync]
root     28395     2  0 Feb10 ?        00:00:00 [bioset]
avahi    30448     1  0 Feb10 ?        00:00:00 avahi-daemon: running [yosec.local]
avahi    30449 30448  0 Feb10 ?        00:00:00 avahi-daemon: chroot helper
root     31524     1  0 Feb10 ?        00:00:04 /usr/sbin/NetworkManager --no-daemon
root     31528     1  0 Feb10 ?        00:00:00 /usr/lib/policykit-1/polkitd --no-debug
root     31944     1  0 Feb10 ?        00:00:00 /usr/sbin/minissdpd -i 0.0.0.0
root     31979     1  0 Feb10 ?        00:00:00 /usr/sbin/ModemManager

但是,docker ps显示正在运行的容器。所以我有点困惑:

代码语言:javascript
复制
sheldon@yosec:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0929b795f4c0        ubuntu:latest       "/bin/bash"         26 minutes ago      Up 26 minutes                           modest_stallman
e2c70f53435c        ubuntu:latest       "/bin/bash"         27 minutes ago      Up 27 minutes                           cranky_bell
f4a2cfb5bdb8        ubuntu:latest       "/bin/bash"         28 minutes ago      Up 28 minutes                           sad_snyder
a5f930397758        ubuntu:latest       "/bin/bash"         29 minutes ago      Up 29 minutes                           nostalgic_poitras
5566e0e92e66        ubuntu:latest       "/bin/bash"         29 minutes ago      Up 29 minutes                           sharp_williams
2ca098323e64        ubuntu:latest       "/bin/bash"         35 minutes ago      Up 35 minutes                           clever_banach

有什么问题吗?

我知道这可能不是做事情的最好方法,但是现在我只是跟着学着和Docker打交道。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-11 13:25:28

我并不100%肯定您的本地env是如何设置的,但是如果您在同一台机器上运行该ps -ef,则可能会有一些/bin/bash是您的容器。

当你用序列分离一个容器时,它不会杀死你的容器,它会分离。为了重新掌握它,您可以运行docker attach <container name or container id>

然而,即使我没有看培训录像,你的例子是错误的。您启动一个已经分离的容器(使用docker run -d),因此如果您试图在之后分离,它将不会影响对接。

为了启动附加的容器以便以后可以分离,您应该使用docker run -i -t ubuntu:latest /bin/bash

当使用-d启动容器时,对接者应该向您显示结果ID,然后可以附加到这个ID上,然后用键顺序分离。

代码语言:javascript
复制
ID=$(docker -i -d ubuntu:latest /bin/bash)
# We are not in docker, still on our shell
docker attach $ID
# We are now attached to the container
# Exectute Ctrl-p Ctrl-Q
# The container is now detached and we are back to our shell
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35337944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档