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
# 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
# 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
# sudo docker exec -i -t loving_heisenberg /bin/bash #by Name
Step 4: To exit bash without leaving bash running in a rogue process
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.
Latest posts by Rajesh Kumar (see all)
- What is Xray in Jira? - April 9, 2021
- How to build jobs in jenkins when a change is pushed to Bitbucket - April 8, 2021
- How to trigger a jenkins job when code is pushed to github using “GitHub hook trigger for GITScm polling” - April 8, 2021