-
-
Save laszlovandenhoek/a3b7e5b9b587609ee9f0050538a2ee8a to your computer and use it in GitHub Desktop.
A shell script to quickly inspect a particular file in a docker image, without having to run it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Check if the correct number of arguments is provided | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <image> <source_path>" | |
exit 1 | |
fi | |
# Assign arguments to variables | |
image="$1" | |
source_path="$2" | |
# Create a temporary directory to store the extracted file | |
temp_dir=$(mktemp -d) | |
destination_path="$temp_dir/$(basename "$source_path")" | |
# Extract the file from the Docker image | |
container_id=$(docker create "$image") | |
docker cp "$container_id:$source_path" "$destination_path" | |
docker rm "$container_id" | |
# Check if the path exists | |
if [ -e "$destination_path" ]; then | |
# Use VISUAL if set, else EDITOR, else default to vi | |
if [ -n "$VISUAL" ]; then | |
"$VISUAL" "$destination_path" | |
elif [ -n "$EDITOR" ]; then | |
"$EDITOR" "$destination_path" | |
else | |
vi "$destination_path" | |
fi | |
else | |
echo "Failed to extract the file from the image." | |
fi | |
# Clean up the temporary directory | |
rm -rf "$temp_dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment