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.

  • managing multiple mesos marathon json configurations for deployment
  • How to run a CMD and open Bash when running a docker container?
  • How to yank to host clipboard from inside a Docker container?
  • Are there any simple python packages that will run a prebuilt docker image
  • How can I keep container running on Kubernetes?
  • Escaping Docker attach one started from bash script
  • Cache docker images on Travis CI
  • creating new SSH keys during docker run
  • How does Docker Swarm load balance?
  • How to deploy a self-building Docker image to make changes to itself in respect to the local environment?
  • Installing docker on Ubuntu 16.10
  • Docker Compose LAMP Database connection error
  • 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:

    #!/bin/bash
    
    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
    else
        echo "No docker container with name: $name is running"
    fi
    

    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.