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 alepez/64a5f1f466c0d294b326367c24743282 to your computer and use it in GitHub Desktop.
Save alepez/64a5f1f466c0d294b326367c24743282 to your computer and use it in GitHub Desktop.
Run Linux ARM executable inside Docker on x86 host

Say that you have compiled an executable for a Linux ARM system and you want to test it inside a Linux x86 system. Docker is able to use qemu to enable execution of different multi-architecture containers.

Execute the register script that registers binfmt_misc handlers for all supported processors except the current one in it when running the container.

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

You have a statically linked executable in /home/user/app_dir/app, just let it be accessible inside an arm docker container, e.g. by mounting the current directory as a volume:

MY_APP_DIR=/home/user/app_dir
docker run --rm -ti -v ${MY_APP_DIR}:/test arm32v7/alpine sh

Inside docker container:

cd /test
./app

If the executable is dynamically linked, you'll get an error like that:

qemu-arm-static: Could not open '/lib/ld-linux-armhf.so.3': No such file or directory

You need to find all needed dynamic libraries.

If you have (cross) compiled that executable or you can run it somewhere, you should be able to get those libraries. Example: you have a sysroot in /home/user/sdk/sysroot

On your PC:

export SYSROOT=/home/user/sdk/sysroot
find $SYSROOT -name ld-linux-armhf.so.3 -exec cp {} ${MY_APP_DIR} \;

Inside the container:

cd /test
export LD_LIBRARY_PATH=$(pwd)
./ld-linux-armhf.so.3 --library-path $(pwd) ./app

Now you may get other errors about libraries not found:

./app: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory

You need to get missing libraries from sysroot:

On your PC:

find $SYSROOT -name libm.so.6 -exec cp {} ${MY_APP_DIR} \;

Repeat this for every missing library, until you can start your executable without problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment