Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save normoes/a797cd93eb428bd694ff654e0157c603 to your computer and use it in GitHub Desktop.
Save normoes/a797cd93eb428bd694ff654e0157c603 to your computer and use it in GitHub Desktop.
Get files and information from a docker container

This can be used to retreive files/binaries/information from docker containers.

#!/bin/bash

set -Eeuo pipefail

mkdir ./binary || true

# build most recent docker image
docker build --pull -t <image_name> .

# disable entrypoint
# keep the container alive
docker run --rm -d -v $PWD/binary:/binary --name=<container_name> --entrypoint="" <image_name> sh -c "while true; do sleep 1; done" || true
# remove old files
docker exec <container_name> rm -rf /binary/*
# get binary version
docker exec <container_name> sh -c '<some_binary> -V > /binary/version.txt 2>&1'
# get release information
docker exec <container_name> sh -c 'cat /etc/os-release > /binary/system.txt'
# get dependencies
docker exec <container_name> sh -c 'ldd $(command -v <some_binary>) > /binary/dependencies.txt'
# get binary
docker exec <container_name> cp /usr/sbin/<some_binary> /binary/
# force remove the container again
docker container rm -f <container_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment