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.

  • How to SSH into Docker?
  • Why rancher service disconnected sometimes?
  • Task on marathon never ends
  • Permission issues with own built Docker container with Elasticsearch 2.1
  • Bluemix - IBM Containers problems for US South?
  • docker build access host folder
  • Hooking subprocess logs into main log output in Docker
  • Logstash with fluent input codec not working
  • error executing curl command in dockerfile
  • How to mount host directory in docker container?
  • How to push into gitlab again when the docker-volume or the server data is recreated?
  • Troubles using docker-machine to setup Swarm
  • 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.