2015年6月20日 星期六

[ 常見問題 ] How to get bash\ssh inside runned container (run -d)?

Source From Here
Question
I want to ssh or bash into running docker container. Please, see example:
$ sudo docker run -d webserver
webserver is clean image from ubuntu:14.04
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
665b4a1e17b6 webserver:latest /bin/bash ... ... 22/tcp, 80/tcp loving_heisenberg

Now I want to get something like this (go into running container):
$ sudo docker run -t -i webserver # or maybe 665b4a1e17b6 instead
$ root@42f1e37bd0e5:/# // However when I run the line above I get new CONTAINER ID

Previously I used Vagrant so I want to get behavior similar to vagrant ssh. Please, could anyone help me?

How-To
The answer is docker's attach command. So for my example above the solution will:
$ sudo docker attach 665b4a1e17b6 #by ID
or
$ sudo docker attach loving_heisenberg #by Name
$ root@665b4a1e17b6:/#

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:
$ sudo docker exec -i -t 665b4a1e17b6 bash #by ID
or
sudo docker exec -i -t loving_heisenberg bash #by Name
$ root@665b4a1e17b6:/#


沒有留言:

張貼留言

[ Java 文章收集 ] 局部敏感哈希 (Locality-Sensitive Hashing, LSH) 方法介紹

Source From  Here   Preface   本文主要介紹一種用於海量高維數據的近似最近鄰快速查找技術—— 局部敏感哈希  ( Locality-Sensitive Hashing, LSH ),內容包括了 LSH 的原理、LSH 哈希函數集、以及 LSH 的一...