Motivation: Oracle Cloud offers an "always-free" tier with Ampere CPU (aarch64 architecture). You can run the latest Ubuntu on it, but unfortunately, Crystal-lang is not available on aarch64.
To run Crystal-lang, I used docker and qemu. NOTE: it is very slow!
First, install docker, docker-compose, and qemu. For qemu, I used the following command to install everything:
sudo apt-get install \
qemu \
qemu-user-static \
qemu-user \
qemu-system-x86 \
qemu-system-arm \
qemu-system-mips \
qemu-system-ppc \
qemu-system-sparc \
qemu-system-m68k \
qemu-system-microblaze \
qemu-system-microblazeel \
qemu-system-sh4 \
qemu-system-sh4eb \
qemu-system-s390x \
qemu-system-riscv64 \
qemu-system-riscv32
Then, test that docker can run foreign platform images:
uname -m
docker run --rm -ti --platform linux/amd64 alpine:latest uname -m
Now it's time to build a Docker image and run it.
Everything has been wrapped in the docker-compose.yml
file.
You should use the docker compose
or docker-compose
command,
depending on your environment.
Thanks to build args, it's possible to solve user permission issues. Docker image runs as a host user. To build the image, use the following command:
docker compose build \
--build-arg DOCKER_USER=$(whoami) \
--build-arg DOCKER_USER_ID=$(id --user) \
--build-arg DOCKER_GROUP_ID=$(id --group)
And run it:
docker compose run -i crystal crystal ./hello-world.cr
Result:
Hello from x86_64
Finally, note that Crystal is available in both Alpine and Ubuntu flavors. You can check the Dockerfile for the FROM instruction.