主要目的是为了帮助需要的用户从 linux/amd64
或 linux/arm64
快速迁移到 linux/loong64
。
使用相同的 Dockerfile
,构建包含linux/amd64
linux/arm64
linux/loong64
三种架构镜像,在linux/amd64
或linux/arm64
验证无问题后,基本在linux/loong64
上也能正常运行。
| Architecture | Arch | OS/Arch |
| :-------------- | :-------- | :------------ |
| x86_64 | amd64 | linux/amd64 |
| aarch64 | arm64 | linux/arm64 |
| loongarch64 | loong64 | linux/loong64 |
龙芯提供了官方镜像仓库 cr.loongnix.cn,可以直接使用,如无自己构建的需求可以直接使用。
linux/loong64
基础 debian:buster-slim
镜像制作可以参考 Loongson-Cloud-Community/debian:buster-slim
有两个问题需要注意:
懒人专用:
具体构建说明:
# 部署 docker, 参考 https://bbs.loongarch.org/d/80-docker-buildx-compose
# docker binaries
$ wget https://github.com/wojiushixiaobai/docker-ce-binaries-loongarch64/releases/download/v26.1.3/docker-26.1.3.tgz
$ tar -xf docker-26.1.3.tgz
$ cp docker/* /usr/local/bin/
# systemd
$ wget https://github.com/wojiushixiaobai/docker-ce-binaries-loongarch64/raw/master/docker.service -O /etc/systemd/system/docker.service
# docker start
$ systemctl start docker
# docker plugins
$ mkdir -p /usr/libexec/docker/cli-plugins
# docker-compose
$ wget -O /usr/libexec/docker/cli-plugins/docker-compose https://github.com/wojiushixiaobai/compose-loongarch64/releases/download/v2.27.1/docker-compose-linux-loongarch64
$ chmod +x /usr/libexec/docker/cli-plugins/docker-compose
$ docker compose version
Docker Compose version v2.27.1
# buildx
$ wget -O /usr/libexec/docker/cli-plugins/docker-buildx https://github.com/wojiushixiaobai/buildx-loongarch64/releases/download/v0.14.1/buildx-v0.14.1-linux-loongarch64
$ chmod +x /usr/libexec/docker/cli-plugins/docker-buildx
$ docker buildx version
github.com/docker/buildx v0.14.1
# 获取源代码,也可以参考 https://github.com/Loongson-Cloud-Community/dockerfiles/tree/main/library/debian/buster-slim 自行构建
$ cd ~
$ git clone -b dist-loongarch64 --depth=1 https://github.com/wojiushixiaobai/docker-debian-artifacts
$ cd docker-debian-artifacts/stable/slim
$ docker build -t debian:buster-slim .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
debian buster-slim 4a773384bfe1 5 days ago 72.5MB
构建出 debian:buster-slim
后,就能基于debian:buster-slim
构建其他的镜像,如 golang
python
node
等等..
以 python
为例,通过 Docker Hub 可知其源码仓库github/docker-library
我们可以尝试构建 3.11
版本
$ cd ~
$ git clone --depth=1 https://github.com/docker-library/python
$ cd python/3.11
# 复制一份代码供修改使用
$ cp -a slim-bullseye slim-buster
# 修改引用镜像为 debian:buster-slim
$ cd slim-buster
$ sed 's@FROM debian:bullseye-slim@FROM debian:buster-slim@g' Dockerfile
# 构建
$ docker buildx build -t python:3.11-slim-buster . --load
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python 3.11-slim b7c268c75484 1 hours ago 125MB
debian buster-slim 4a773384bfe1 1 hours ago 72.5MB
其他需要 loongarch64
二进制文件的如 golang
node
等镜像,可以通过修改 Dockerfile
来适配
以 node:18.13
镜像为例
$ cat Dockerfile
FROM debian:buster-slim
RUN groupadd --gid 1000 node \
&& useradd --uid 1000 --gid node --shell /bin/bash --create-home node
ENV NODE_VERSION 18.13.0
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& case "${dpkgArch##*-}" in \
amd64) ARCH='x64';; \
ppc64el) ARCH='ppc64le';; \
s390x) ARCH='s390x';; \
arm64) ARCH='arm64';; \
armhf) ARCH='armv7l';; \
i386) ARCH='x86';; \
loongarch64) ARCH='loong64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
&& set -ex \
# libatomic1 for arm
&& apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& for key in \
4ED778F539E3634C779C87C6D7062848A1AB005C \
141F07595B7B3FFE74309A937405533BE57C7D57 \
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
61FC681DFB92A079F1685E77973F295594EC4689 \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
108F52B48DB57BB0CC439B2997B01419BD92F80A \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& \
if [ "${ARCH}" = "loong64" ]; then \
curl -fsSLO --compressed "http://ftp.loongnix.cn/nodejs/LoongArch/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz"; \
else \
curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz"; \
curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc"; \
gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc; \
grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c -; \
rm SHASUMS256.txt.asc SHASUMS256.txt; \
fi \
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
&& apt-mark auto '.*' > /dev/null \
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
# smoke tests
&& node --version \
&& npm --version
ENV YARN_VERSION 1.22.19
RUN set -ex \
&& savedAptMark="$(apt-mark showmanual)" \
&& apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& for key in \
6A010C5166006599AA17F08146C2130DFD2497F5 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& mkdir -p /opt \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& apt-mark auto '.*' > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
# smoke test
&& yarn --version
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD [ "node" ]
我自己已经移植了部分镜像 docker-library-loong64,龙芯也提供了 dockerfiles,可以根据实际需要自行进行构建。
部分软件的移植说明可以参考 移植手册