LOGIN
Sign In or Register
Avatar
Not Registered Yet?

Join Now! It's FREE. Get full access and benefit from this site

Reset My password - Remind Me My username

Username
Password
Remember me

How to get bash or ssh into a running container in background mode?

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 only one instance of shell.
# sudo docker attach 665b4a1e17b6 #by ID
or
# sudo docker attach loving_heisenberg #by Name
 
If we want open new terminal with new instance of container's shell, we just need run the following:
# sudo docker exec -i -t 2e56ad1705b1 /bin/bash #by ID
or
# sudo docker exec -i -t loving_heisenberg /bin/bash #by Name
# root@665b4a1e17b6:/#
 
Step 4: To exit bash without leaving bash running in a rogue process
# exit
 
Notes:
A reminder for boot2docker users: remove sudo
If you are using docker in Linux, you will have to use sudo along with docker commands.
You should try not to run commands as sudo, rather add your user to the docker group and just run normally.
Rate this item
(1 Vote)
Rajesh Kumar

.

Total, Over 12 years of extensive experience in the Software Configuration Management domain having depth knowledge of DevOps, Continuous Integration and Delivery, Configuration Management, Build and Installer, Release Management and Application Management.