Docker: Support x86_64, armv7 and aarch64 docker image #3058
Labels
good first issue
Easy to fix issues, good for newcomers
help wanted
Extra attention is needed
TransByAI
Translated by AI/GPT.
Milestone
ARM server is everywhere, SRS should support linux/amd64, linux/arm/v7 and linux/arm64/v8 image. It also enable us to run SRS on Apple M1 by docker.
Recently, I have noticed a trend, which is the increasing number of ARM servers. However, it seems that ARM is not as easily recognizable as the x64 platform, as there are always various ARM versions that cannot be identified. If SRS could provide ARM docker images, it would be easier to run.
SRS already supports docker images for multiple CPU architectures, as shown in the following image:
Below are the usage and technical background.
Usage
Now SRS supports multiple CPU architectures, refer to ossrs/srs:
linux/amd64
This is the x86_64 architecture, Intel's 64-bit server. Currently, most Linux servers are of this type, and any operating system that uses this chip can use this image. Apple Mac with Intel chips can also use this image.linux/arm/v7
This is the armv7 architecture, which is a 32-bit architecture. For example, Raspberry PI uses this type of server. If you want to use SRS on a PI, you can use this image. I haven't verified it with hardware, so I welcome everyone to test and provide feedback.linux/arm64/v8
This is the armv8 architecture, which is a 64-bit architecture. Currently, most ARM cloud servers use this architecture, and any operating system can use this image. Apple Mac with M1 chips should be able to use this image as well. I don't have the hardware to verify it, so I welcome everyone to test and provide feedback.The usage is the same as before. Docker will select the appropriate image based on the machine's CPU architecture. So there is no change in usage. Here is a simple example:
In China, you can use Alibaba Cloud mirror, for example:
For more examples, you can refer to the Wiki:
Below are additional backgrounds on images that support multi-CPU architectures. If you need to modify the code and build your own image, or if you need support for other CPU architectures, you can refer to the following resources.
Verify
If you need to verify the arm/v7 architecture, you can choose RaspberryPI. Currently, cloud servers are all based on the arm64/v8 architecture.
In fact, SRS can support multiple CPUs, such as x86_64, arm, aarch64, mips, loongarch, etc. Please refer to ST: Adaptation for specific details. However, separate adaptation is required to support these CPUs in docker images.
You can choose cloud servers to verify ARM docker, such as Tencent Cloud ARM, Alibaba Cloud ARM, Huawei Cloud Kunpeng, AWS ARM.
Execute the command to view the CPU architecture of the machine:
# uname -p aarch64
Start Docker and check the CPU architecture in the container:
The development image verification is complete. Let's verify the SRS image on an ARM cloud host with a CPU architecture of
aarch64
, which islinux/arm64/v8
. Execute the following command:It can be seen that Docker has successfully downloaded the image for the
aarch64
architecture. Verification is complete.SRS Image
If you need to build your own multi-CPU architecture image for SRS, you can refer to the details in this section.
To perform the operation, it is very simple. You can simply use the command to package it:
Multiple CPU Image
Previously, the docker for SRS only supported the x86_64 architecture, so it couldn't run on ARM and other CPUs. Please refer to SRS. Actually, images can support multiple architectures, as mentioned in Manually Building Multi-CPU Architecture Images.
To understand Docker's multi-CPU architecture images, let's first try a simple image without any dependencies.
First, create a Dockerfile with the FROM statement prefixed with ARCH:
If you are using a Mac, you need to create a builder, for example:
Then, use docker buildx to build the image:
docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 \ -t ossrs/srs:multiarch-example .
If you need to upload to another registry like Alibaba Cloud, you can run it again. Docker has caching:
docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 \ -t registry.cn-hangzhou.aliyuncs.com/ossrs/srs:multiarch-example .
This way, a multi-CPU architecture image is packaged and uploaded:
This image can be seen on Docker Hub, including multiple CPU architectures.
GitHub Actions
SRS is using GitHub Actions to automatically build the image and upload it to Docker and Aliyun image repositories.
In
.github/workflows/release.yml
, an additional step is required to install buildx.Multiple Repositories
Multi-CPU architecture images cannot be directly pushed to multiple repositories using the usual method. Instead, a separate action needs to be used.
In
.github/workflows/release.yml
, an additional step is required to push to multiple repositories.ARG
The parameter ARCH can only be used in the FROM statement, and it can also be used to make judgments based on the target platform after the FROM statement.
Issues
CentOS7 image does not support
linux/arm/v7
and will result in an error.Execute the command:
docker buildx build --platform linux/arm/v7 .
An error occurred and it has been stuck indefinitely:
Switching to Ubuntu20 will not be a problem.
It can be compiled on all three platforms.
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 .
So SRS is ready to switch to the Ubuntu20 base development image.
Debug Building SRT
To compile SRT for a specific platform, such as
linux/arm/v7
, first package the code.Then modify
trunk/Dockerfile
and compile SRT directly.Execute the command:
This is equivalent to directly compiling SRT, with a short debugging cycle.
TRANS_BY_GPT3
The text was updated successfully, but these errors were encountered: