Skip to the addendum for an automated script.
Define your image and use skopeo to pull the build history and the layer manifest.
IMAGE="docker://SOME_USERNAME/SOME_REPONAME[:OPTIONAL_TAG]"
skopeo inspect --config "$IMAGE" > history.json
skopeo inspect "$IMAGE" > metadata.json
Run this jq command to see a side-by-side mapping of every command to its corresponding SHA256 layer digest. Identify the idx and sha for the instruction that added your target file (e.g., COPY start.sh).
jq -n --slurpfile h history.json --slurpfile m metadata.json '($h[0].history|map(select(.empty_layer|not))) as $h|$m[0].Layers as $l|[range(0;$l|length)|{idx:.,cmd:$h[.].created_by,sha:$l[.]}]'
Update the LAYER_SHA and FILE_TO_EXTRACT variables based on your findings in Step 2. Then, run the following commands to pull the authentication token and download only that specific layer fragment to extract your file.
LAYER_SHA="sha256:PASTE_SHA_FROM_STEP_2_HERE"
FILE_TO_EXTRACT="start.sh"
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$(R="${IMAGE#docker://}"; echo "${R%:*}"):pull" | jq -r .token)
curl -L -H "Authorization: Bearer $TOKEN" "https://registry-1.docker.io/v2/$(R="${IMAGE#docker://}"; echo "${R%:*}")/blobs/$LAYER_SHA" -o fragment.tar.gz
tar -zxvf fragment.tar.gz "$FILE_TO_EXTRACT"
Attached is a Ruby script that automates the procedure and wraps it in a convenient NCurses interface. It expects you to have libncurses-dev, skpoeo, curl, jq, and tar installed and you'll also need the Ruby curses library. All very easy to setup - get with Gemini or similar for assistance if necessary.