Command line shortcut to connect to a docker container [closed]

I would like know if there any shortcut command to connect on docker container without run docker exec -it 'container_id' bash every time.

  • Docker node.js Ctrl+C in Node.Js ssh deploy
  • what is the <my_namespace> in the command ic build -t<my_namespace>/myimage
  • How to cleanup docker?
  • Bad substitution [duplicate]
  • How to send STDIN to docker process
  • What is the difference between Docker Host and Container
  • How do I use the public swagger-generator docker image to generate a client?
  • Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
  • Creating a CAAS using Kubernetes/Docker/Flannel/etcd
  • pod is not starting on gcloud container registry
  • Continuous Delivery on Wordpress using Docker
  • How do you provide a managed file to a Jenkins build using docker.image?
  • 2 Solutions collect form web for “Command line shortcut to connect to a docker container [closed]”

    Here is a shorter command line shortcut to:

    1. Check if a container is running
    2. If running, connect to a running container using docker exec -it <container> bash command:

    Script docker-enter:

    name="${1?needs one argument}"
    containerId=$(docker ps | awk -v app="$name:" '$2 ~ app{print $1}')
    if [[ -n "$containerId" ]]; then
        docker exec -it $containerId bash
        echo "No docker container with name: $name is running"

    Then run it as:

    docker-enter webapp

    I’m using the following alias on OS X:

    alias dex='function _dex(){ docker exec -i -t "$(basename $(pwd) | tr -d "[\-_]")_$1_1" /bin/bash -c "export TERM=xterm; exec bash" };_dex'

    In the same directory as my docker-files, I run “dex php” to enter the PHP container.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.