comcloudway/alpine-cross
1
0
Fork
You've already forked alpine-cross
0
Dockerfile to build Docker images, that allow running commands in chroots of different architectures.
Shell 70.4%
Dockerfile 29.6%
Jakob Meier 47858d52d4
All checks were successful
ci/woodpecker/push/build-guest-amd64 Pipeline was successful
ci/woodpecker/push/build-guest-arm64 Pipeline was successful
Disabled qemu-binfmt on same-arch guests
2023年06月25日 09:25:54 +02:00
.woodpecker Added same-arch cross containers 2023年06月07日 10:19:13 +02:00
docker-entrypoint.sh Disabled qemu-binfmt on same-arch guests 2023年06月25日 09:25:54 +02:00
Dockerfile Renamed project 2023年06月03日 11:22:43 +02:00
LICENSE Added AGPL license 2023年06月03日 09:10:03 +02:00
qemu-user-binfmt.txt Added file from https://git.sr.ht/~postmarketos/pmbootstrap/blob/master/pmb/data/qemu-user-binfmt.txt 2023年06月03日 09:09:03 +02:00
README.org Added woodpecker CI 2023年06月03日 11:27:51 +02:00

alpine-cross

This project allows you to build docker files, that run on one architecture (HOST_ARCH) but execute commands on a different architecture (GUEST_ARCH).

For example, you could build a Docker image, that runs on your x86_64 host CI, using which you can run/build aarch64 binaries.

Dockerfile Build Options

  • GUEST_ARCH, the architecture the container is supposed to emulate (can be any of the architectures, that have an alpine chroot available. You can find a list here).
  • ALPINE_VERSION, allows you to specify which alpine version the chroot runs on. (Might be limited depending on which GUEST_ARCH you chose)
  • CHROOT_DIR, where the chroot is located inside of the Docker container. This is set to /chroot by default, and you probably won't need to change this.

Building

As of writing the docker image can be build by marking the Dockerfile as executable, and then executing it:

chmod +x Dockerfile
./Dockerfile
# if you do not have docker setup to run rootless,
# you might have to prepend sudo or doas to the previous command

If you do not feel comfortable with marking Dockerfiles as executable, you can use the following command instead:

docker build . -t alpine-cross
# if you do not have docker setup to run rootless,
# you might have to prepend sudo or doas to the previous command

BuildX

If you want to build the container for a different HOST_OS, you can use docker buildx:

docker buildx build --platform linux/arm64 . -t alpine-cross
# if you do not have docker setup to run rootless,
# you might have to prepend sudo or doas to the previous command

The following platforms are currently supported by the alpine docker image: (This does not mean that they work, but these are the possible values)

  • amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, riscv64, s390x

For an up-to-date list, you might want to check the alpine docker hub page

Running the container

To run the container, you have to add the --privileged option to docker run.

For example to validate your setup, you could run the following command.

docker run --privileged -it alpine-cross uname -m
# if you do not have docker setup to run rootless,
# you might have to prepend sudo or doas to the previous command

This should print the architecture name of the GUEST_ARCH

As you may have noticed from the command above, the chroot accepts command line parameters. By using them, you can also start a shell:

docker run --privileged -it alpine-cross ash
# if you do not have docker setup to run rootless,
# you might have to prepend sudo or doas to the previous command

Persistence

To persist the chroot you have to bind mount the CHROOT_DIR.

Prebuilds

You can find prebuild containers on codeberg.

Resources

For more information on binfmt_misc, I found the following websites helpful: