docker--通过attach命令进入容器

启动一个ubuntu的容器:
# docker run -idt ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
b6f892c0043b: Pull complete
55010f332b04: Pull complete
2955fb827c94: Pull complete
3deef3fcbd30: Pull complete
cf9722e506aa: Pull complete
Digest: sha256:382452f82a8bbd34443b2c727650af46aced0f94a44463c62a9848133ecb1aa8
Status: Downloaded newer image for ubuntu:latest
ad6ffafcaa17b824f08fe4897b67e4772137001bfd601009281592f2c9abd06e


查看容器状态:

# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad6ffafcaa17 ubuntu "/bin/bash" 11 seconds ago Up 10 seconds pensive_easley
8e5842cb984a nginx:v3 "nginx -g 'daemon ..." About an hour ago Exited (0) 49 seconds ago webserver3
50f00085b48f nginx:v2 "nginx -g 'daemon ..." 5 hours ago Exited (0) About an hour ago webserver2
e033ce3a2d90 nginx "nginx -g 'daemon ..." 6 hours ago Exited (0) About an hour ago webserver1


通过attach命令进入到容器执行命令:

# docker attach pensive_easley
root@ad6ffafcaa17:/#
root@ad6ffafcaa17:/# cat /etc/*ease*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
root@ad6ffafcaa17:/# exit