1.docker attach介绍
docker attach命令是用来进入一个正在运行的docker容器
2.docker attach用法
docker attach [参数] container
[root@centos79 ~]# docker attach --help
Usage: docker attach [OPTIONS] CONTAINER
Attach local standard input, output, and error streams to a running container
Aliases:
docker container attach, docker attach
Options:
--detach-keys string Override the key sequence for detaching a container
--no-stdin Do not attach STDIN
--sig-proxy Proxy all received signals to the process (default true)
[root@centos79 ~]#
3.实例
3.1.进入启动的docker容器
命令:
docker attach 800d
[root@centos79 ~]# docker ps -a | grep 800d
800d0759315f centos:centos7 "/bin/bash" 20 hours ago Up 14 seconds gracious_bohr
[root@centos79 ~]# docker attach 800d
[root@800d0759315f /]# exit
exit
[root@centos79 ~]# docker ps -a | grep 800d
800d0759315f centos:centos7 "/bin/bash" 20 hours ago Exited (0) 6 seconds ago gracious_bohr
[root@centos79 ~]#
docker attach containerid/containername命令进入到正在运行的docker容器后,输入exit命令或Ctrl + d退出容器后,原来正在运行的容器也会停止。
3.2.进入启动的容器退出不停止
命令:
docker attach 800d
[root@centos79 ~]# docker ps -a | grep 800d
800d0759315f centos:centos7 "/bin/bash" 20 hours ago Up 3 seconds gracious_bohr
[root@centos79 ~]# docker attach 800d
[root@800d0759315f /]# read escape sequence
[root@centos79 ~]# docker ps -a | grep 800d
800d0759315f centos:centos7 "/bin/bash" 20 hours ago Up 27 seconds gracious_bohr
[root@centos79 ~]#
docker attach containerid/containername命令进入到正在运行的docker容器后,输入Ctrl +p+q退出容器后,原来正在运行的容器不会停止
另外,使用docker exec命令也可以进入正在运行的docker容器,不过输入exit命令或Ctrl +d退出容器后,原来正在运行的容器不会停止,这是docker exec命令和docker attach命令的区别