Automate opening bash shell on a running docker

Setting up a development environment that is deployable has always been a complicated task for data scientists. In my case, I have a bunch of environments, each designed for different purposes. For example, I use R for time-series forecasting and descriptive statistics, while using Python (with Scikit-Learn, Tensorflow, and sometimes Caffe) for deep learning and reinforcement learning. It is almost impossible for me to have one environment for every purpose.

Docker has saved my life. It’s an elegant solution for every trouble you’ve ever got with environment settings. If you have not read about it, you should do it now.

To make my life easier, I’ve created several bash scripts to automate some docker tasks that I usually do. You can check the list here. My favorite script is to open a bash shell on a running docker. To execute the bash sell command on a particular docker, you need to know its ID, like this:

$ docker exec -it $DockerID /bin/bash

Since the DockerID will change every time you run a new image, you need to list all of the running dockers and pick the one that you want to access to. This is not a big deal, until you have to do it hundreds times. The following script will list and let you pick your target docker. A simple solution for a small daily issue.

Like what you read? Give Dang Ha The Hien a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.