dockerbash - Making docker exec -it Suck Less
source link: https://fuzzyblog.io/blog/docker/2019/11/21/dockerbash-making-docker-exec-it-suck-less.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
dockerbash - Making docker exec -it Suck Less
Nov 21, 2019
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
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.
Recommend
-
28
The C language is very powerful, widely usedâparticularly in the Linux kernelâand very dangerous. One of the Linux engineers outlines how developers can cope with the programming language's security weaknesses.
-
7
Can we improve products by making them less efficient? Published: Thursday, 25 July 2019 ∙ Updated: Thursday, 7 November 2019 Read time: 5 Minutes I can’t even remember when I last visited an art exhibition, so...
-
2
Making risk less risky The Intrazone podcast%3CLINGO-SUB%20id%3D%22lingo-sub-2067837%22%20slang%3D%22en-US%22%3E%E2%80%9CMaking%20risk%20less%20risky%E2%80%9D%20%3Astudio_microphone%3A%3C%2Fimg%3E%20%E2%80%93%20The%20Intrazone%20podcast%3C%2FLIN...
-
3
Privacy and SecuritySignal's CEO Just Hacked the Cops' Favorite Phone Cracking Tool and Became a LegendScreenshot: Lucas Ropek/Signal
-
6
-
9
-
5
docker exec 失败问题排查之旅 2022-01-09 ...
-
5
Ten Tips to Make Conference Talks Suck Less Posted at Jun 23, 2022 Every so often, I come across some conference talk which is highly interesting in terms of its actual contents, but...
-
0
The EV charging situation in the US is about to suck a little less / President Joe Biden just approved $900 million in the first tranche of funding Sep 14, 2022, 9:21 PM UTC|
-
2
5 books to read to make work suck lessRead up on the most pressing...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK