Ask Ubuntu上有人问怎么能login或者ssh一个运行的docker容器。
例如
1 | $ sudo docker run -d webserver |
想进行这样的登录:
1 | $ sudo docker run -t -i webserver (or maybe 665b4a1e17b6 instead) |
The answer is docker's attach command. So for my example above the solution will:
1 | $ sudo docker attach 665b4a1e17b6 #by ID |
UPDATE: (docker >= 1.3) Thanks to WiR3D user who suggested another way to get container's shell. If we use attach we can use only one instance of shell. So if we want open new terminal with new instance of container's shell, we just need run the following:
1 | $ sudo docker exec -i -t 665b4a1e17b6 bash #by ID |
