Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Docker»How to Get Shell Access to Running Docker Container

    How to Get Shell Access to Running Docker Container

    RahulBy RahulMarch 29, 20172 Mins ReadUpdated:April 26, 2017

    In our previous docker tutorials your learned about how to Install Docker on CentOS or Install Docker on Debian based system. Also, write tutorials about how to create or delete docker containers. This tutorial will help you to get shell access to your running docker container.

    #1. Using Docker Attach

    You can get bash shell access in your docker container with attach command. But your docker container must be started with /bin/bash.

    Use below syntax to get shell access of docker container.

    $ sudo docker attach <CONTAINER ID/NAME>
    

    For example, your docker container is running with id 76debad837d2 and name happy_tecadmin. Use one of the following commands with attach method.

    Using Container ID:

    $ sudo docker attach 76debad837d2
    

    Using Container Name:

    $ sudo docker attach happy_tecadmin
    

    #2. Using Docker Exec

    If docker container was not started with /bin/bash command. Then you can’t use attach command. Now, you need to use exec command to create bash in your container. Make sure you are using Docker version >= 1.3.

    Use below syntax to get shell access of docker container.

    $ sudo docker exec -it <CONTAINER ID/NAME> bash
    

    For example, your docker container is running with id 76debad837d2 and name happy_tecadmin. Use one of the following commands with exec method.

    Using Container ID:

    $ sudo docker exec -it 76debad837d2  bash
    

    Using Container Name:

    $ sudo docker exec -it happy_tecadmin bash
    
    bash Container Docker shell
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleTop 5 WordPress Security Plugins To Keep Your Website Safe
    Next Article How to Exclude Specific Packages from Yum Update

    Related Posts

    How to Backup Website to Amazon S3 using Shell Script

    Updated:March 24, 20222 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    Bash Sequence Expression (Define Range)

    Updated:January 12, 20222 Mins Read

    Bash Select Command (Create Menu in Shell Scripts)

    Updated:December 10, 20212 Mins Read

    (Resolved) -bash: /bin/mv: Argument list too long

    Updated:January 13, 20222 Mins Read

    Bash Break and Continue

    Updated:November 9, 20213 Mins Read

    1 Comment

    1. rajani on May 18, 2019 6:46 am

      Great Article !! Thanks for sharing..

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.