docker attach命令使用

docker attach主要用来进入容器内部,之前创建了一个ubuntu的镜像,具体过程看之前的日志,现在进去瞅瞅

[[email protected] ~]# docker attach ubuntu
[email protected]:/# 
[email protected]:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02 
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:2406 (2.4 KB) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback 
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1 
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

[email protected]:/# 


[email protected]:/# pwd
/
[email protected]:/# ll
total 4
drwxr-xr-x. 1 root root 6 Jul 4 11:31 ./
drwxr-xr-x. 1 root root 6 Jul 4 11:31 ../
-rwxr-xr-x. 1 root root 0 Jul 4 11:31 .dockerenv*
drwxr-xr-x. 2 root root 4096 May 15 01:25 bin/
drwxr-xr-x. 2 root root 6 Apr 10 2014 boot/
drwxr-xr-x. 5 root root 360 Jul 4 11:31 dev/
drwxr-xr-x. 1 root root 66 Jul 4 11:31 etc/
drwxr-xr-x. 2 root root 6 Apr 10 2014 home/
drwxr-xr-x. 12 root root 208 May 15 01:25 lib/
drwxr-xr-x. 2 root root 34 May 15 01:24 lib64/
drwxr-xr-x. 2 root root 6 May 15 01:23 media/
drwxr-xr-x. 2 root root 6 Apr 10 2014 mnt/
drwxr-xr-x. 2 root root 6 May 15 01:23 opt/
dr-xr-xr-x. 214 root root 0 Jul 4 11:31 proc/
drwx------. 2 root root 37 May 15 01:25 root/
drwxr-xr-x. 1 root root 21 May 15 21:21 run/
drwxr-xr-x. 1 root root 44 May 15 21:21 sbin/
drwxr-xr-x. 2 root root 6 May 15 01:23 srv/
dr-xr-xr-x. 13 root root 0 Apr 11 2018 sys/
drwxrwxrwt. 2 root root 6 May 15 01:25 tmp/
drwxr-xr-x. 1 root root 18 May 15 01:23 usr/
drwxr-xr-x. 1 root root 17 May 15 01:25 var/
[email protected]:/# free -m
total used free shared buffers cached
Mem: 3935 3670 265 12 5 2024
-/+ buffers/cache: 1640 2295
Swap: 8191 0 8191

可以进去玩一玩,但是退出要注意:不能使用exit或者ctrl+c,这样的话,相当于把容器直接停止

要退出容器,应该使用ctrl+p,此时屏幕没反应,然后使用ctrl+q,就可以退出虚拟终端了,而且容器也在运行

[email protected]:/# read escape sequence
[[email protected] ~]# 
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7103a04f97d3 ubuntu:14.04 "/bin/bash" 22 minutes ago Up 22 minutes ubuntu

不过特别注意,官方并不推荐使用这个命令进入开启了交互模式的容器,即使加了-t,后台运行,也不推荐

此条目发表在Docker分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注