{"id":471,"date":"2016-02-23T11:51:34","date_gmt":"2016-02-23T11:51:34","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2016\/02\/23\/how-to-get-bash-or-ssh-into-a-running-container-in-background-mode\/"},"modified":"2017-12-17T11:11:24","modified_gmt":"2017-12-17T11:11:24","slug":"how-to-get-bash-or-ssh-into-a-running-container-in-background-mode","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-get-bash-or-ssh-into-a-running-container-in-background-mode\/","title":{"rendered":"How to get bash or ssh into a running container in background mode?"},"content":{"rendered":"<div><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3196 size-full aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2016\/02\/bash-or-ssh-into-a-running-1-1.png\" alt=\"bash-or-ssh-into-a-running-container\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2016\/02\/bash-or-ssh-into-a-running-1-1.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2016\/02\/bash-or-ssh-into-a-running-1-1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/div>\n<div><strong>How to get bash or ssh into a running container in background mode?<\/strong><\/div>\n<div><\/div>\n<div><strong>Step 1: First of all, try to find your active container by running<\/strong><\/div>\n<div># docker ps<\/div>\n<div>or<\/div>\n<div># docker ps -a<\/div>\n<div><\/div>\n<div><strong>Step 2: If the container is not running,<\/strong><\/div>\n<div># docker start your_id<\/div>\n<div><\/div>\n<div><strong>Step 3: If we use attach we can use only one instance of shell.<\/strong><\/div>\n<div># sudo docker attach 665b4a1e17b6 #by ID<\/div>\n<div>or<\/div>\n<div># sudo docker attach loving_heisenberg #by Name<\/div>\n<div><\/div>\n<div>If we want open new terminal with new instance of container&#8217;s shell, we just need run the following:<\/div>\n<div># sudo docker exec -i -t 2e56ad1705b1 \/bin\/bash #by ID<\/div>\n<div>or<\/div>\n<div># sudo docker exec -i -t loving_heisenberg \/bin\/bash #by Name<\/div>\n<div># root@665b4a1e17b6:\/#<\/div>\n<div><\/div>\n<div><strong>Step 4: To exit bash without leaving bash running in a rogue process<\/strong><\/div>\n<div># exit<\/div>\n<div><\/div>\n<div><strong>Notes:<\/strong><\/div>\n<div>A reminder for boot2docker users: remove sudo<\/div>\n<div>If you are using docker in Linux, you will have to use sudo along with docker commands.<\/div>\n<div>You should try not to run commands as sudo, rather add your user to the docker group and just run normally.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>How to get bash or ssh into a running container in background mode? Step 1: First of all, try to find your active container by running # docker ps or # docker ps -a Step 2: If the container is not running, # docker start your_id Step 3: If we use attach we can use&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3196,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[1196,137,1194,567,545,321,1195,896,1197],"class_list":["post-471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-background","tag-bash","tag-container","tag-docker","tag-how","tag-mode","tag-running-container","tag-ssh","tag-ssh-into-a-container"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":3274,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/471\/revisions\/3274"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3196"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}