# dockerbash: Simplifying Interactive Shell Access with docker exec

DevFeed: [dockerbash: Simplifying Interactive Shell Access with docker exec](<https://devfeed.tech/articles/dockerbash-making-docker-exec-it-suck-less-28155.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/docker/2019/11/21/dockerbash-making-docker-exec-it-suck-less.html>)

Author: Fuzzygroup

Published: 2019-11-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Docker](<https://devfeed.tech/topics/docker.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [DevOps](<https://devfeed.tech/topics/devops.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [command](<https://devfeed.tech/tags/command.md>), [devops](<https://devfeed.tech/tags/devops.md>), [docker](<https://devfeed.tech/tags/docker.md>), [how-to](<https://devfeed.tech/tags/how-to.md>)

## AI overview

This tutorial introduces dockerbash, a Bash script that finds a running Docker container by a supplied name fragment and opens an interactive Bash shell inside it with docker exec. It also recommends installing the script through DevOps tooling such as Ansible.

## Source excerpt

Docker is a container technology that allows you to package up a series of different technologies under (generally) a *nix style operating system. As things deployed with Docker are generally deployed under a *nix style operating system, it isn't uncommon to want to open a shell into your Docker environment for debugging purposes. You can easily do this with: docker exec -it CONTAINER_HASH /bin/bash The CONTAINER_HASH is a value like 311ab7fe0ea1. This value is fetched from a docker ps command like this: docker ps | grep police The term 'police' is just some bit of text that identifies the docker process that is running. Here's an example of this output: ❯ docker ps | grep police 311ab7fe0ea1 img-captain-police-crawl:51 "/bin/sh -c 'puma -C..." 4 hours ago Up 4 hours What I'd really like is a command like this: dockerbash police and have that do the underlying work to generate the docker exec statement. A little bit of bash scripting gave me this script: #!/bin/bash if [ -z $1 ]; then echo "You need to specify the name of the container you want to get into like:" echo "dockerbash police" else pid=`docker ps | grep $1 | awk '{print $1}'` docker exec -it $pid /bin/bash fi Save the lines above as dockerbash and make it executable. After that you can much more easily get a shell prompt inside your docker containers. Bash References Bash Cheat Sheet How to Set a Variable in Bash How to Use Awk to Get the First Variable Where Does dockerbash Live? You cannot store dockerbash in the project that you are deploying via Docker because it needs to exist on the machine that runs your Docker containers, not within your Docker container. My recommendation is that you have your DevOps tooling such as Ansible install this script.