Basic Environment#
Operating System: openEuler 22.03 (LTS-SP2)
Software: Docker-26.1.2, Docker Compose-v2.27.0
Installing Docker#
(1) Configure yum repository to download Docker.
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/docker-ce.repo
(2) Install the latest version of Docker and Docker Compose.
# Download dependencies and Docker, Docker Compose
yum install -container-selinux
yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
(3) Change Docker's data directory to “/data/dockerData” and configure the Docker image source.
echo '{
"data-root": "/data/dockerData",
"registry-mirrors": ["https://dockerhub.icu"]
}' > /etc/docker/daemon.json
(4) Start the Docker service and set it to start on boot.
systemctl start docker
systemctl enable docker
Use register
to Register Supported Architecture Interpreters#
docker run --rm --privileged multiarch/qemu-user-static:register --reset
Check if the binary format interpreter is enabled; if it shows enabled
, it is activated.
ls /proc/sys/fs/binfmt_misc/
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
Pull Basic ARM Image#
Taking the httpd image as an example, pull the arm64 architecture httpd image on the x86 server, where --platform=arm64
specifies the architecture of the image to pull as arm64, and --platform=amd64
pulls the x86 architecture image.
docker pull --platform=arm64 httpd:latest
Define Dockerfile to Create New Image#
There are two ways to create a new arm image using a Dockerfile: one is to directly download the qemu-aarch64-static
program and copy it into the image during the build; the other is to pull the multiarch/qemu-user-static:x86_64-aarch64
image and copy the qemu-aarch64-static
program into the httpd
image through multi-stage builds.
Method 1: Download Program and Copy Directly#
(1) When downloading the qemu-aarch64-static
program, you can either download the program directly or download its compressed package and then extract it.
# Download the program directly (recommended)
wget https://github.com/multiarch/qemu-user-static/releases/download/v7.2.0-1/qemu-aarch64-static
# Download its compressed package first, then extract
wget https://github.com/multiarch/qemu-user-static/releases/download/v7.2.0-1/qemu-aarch64-static.tar.gz
tar -vzxf qemu-aarch64-static.tar.gz
# Grant executable permissions
chmod +x /usr/bin/qemu-aarch64-static
(2) Create a Dockerfile, building a new image based on the httpd image. The qemu-aarch64-static
program must be in the same directory as the Dockerfile. The specific content of the Dockerfile is as follows:
FROM httpd:latest
# Copy the qemu-aarch64-static program into the /usr/bin/ directory of the image
COPY ./qemu-aarch64-static /usr/bin/qemu-aarch64-static
# Copy the test html file to the relevant directory of the image
COPY ./index.html /usr/local/apache2/htdocs/
(3) Specify the architecture for building, execute the command to start building the new image, and after the build is complete, check the architecture of the new image and export it as a tar file for verification on the arm server.
# Build the image
docker build --platform arm64 -t httpd:1.00 .
# Check the architecture of the new image
docker inspect httpd:1.00 | grep Architecture
# Export the image as a tar file
docker save -o httpd.tar httpd:1.00
Method 2: Copy Through Multi-Stage Build of Images#
(1) Create a Dockerfile, building the new image in two stages. The first stage retrieves the qemu-aarch64-static
program from the multiarch/qemu-user-static
image, and the second stage builds the new image based on the httpd image. The specific content of the Dockerfile is as follows:
# First stage: Get the qemu-aarch64-static program from the multiarch/qemu-user-static image
FROM multiarch/qemu-user-static:x86_64-aarch64 as qemu
# Second stage: Build the new image based on the httpd image
FROM httpd:latest
# Copy the qemu-aarch64-static program into the /usr/bin/ directory of the image
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin/
# Copy the test html file to the relevant directory of the image
COPY ./index.html /usr/local/apache2/htdocs/
(2) Specify the architecture for building, execute the command to start building the new image, and after the build is complete, check the architecture of the new image and export it as a tar file for verification on the arm server.
# Build the image
docker build --platform arm64 -t httpd:1.00 .
# Check the architecture of the new image
docker inspect httpd:1.00 | grep Architecture
# Export the image as a tar file
docker save -o httpd.tar httpd:1.00
Extension: The multi-stage build copy can also be directly replaced with this docker command.
docker build --rm --platform arm64 -t "httpd:1.00" -<<EOF
FROM multiarch/qemu-user-static:x86_64-aarch64 as qemu
FROM httpd:latest
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
COPY ./index.html /usr/local/apache2/htdocs/
EOF
Verification on ARM Server#
Import the new image tar file into the arm server, create a new container to verify whether the image is usable and whether the html file in the image is effective.
# Import the new image
docker load -i httpd.tar
# Check the architecture of the new image
docker inspect httpd:1.00 | grep Architecture
# Run the new container
docker run -itd --name test httpd:1.00
# Check the running status
docker ps
# Check the container IP
docker inspect test | grep IPAddress
# Access the uploaded html file to see if it is effective
curl 172.17.0.2