前言
由于我的电脑内存太小,不想多装台虚拟机来做实验,只能租了台华为云的服务器。可惜镜像市场中的CPU 架构是aarch64的。初期下载docker-compose时,我发现官方提供的二进制包时基于amd64的。因此官方提供的二进制包不能兼容我的aarch64。

另寻他法
下载

首先安装docker
获取软件包获取“Docker Compose-1.22.0”安装包。
cd /usr/local/src
git clone https://github.com/ubiquiti/docker-compose-aarch64.git
cd /usr/local/src
git clone https://github.com/ubiquiti/docker-compose-aarch64.git
安装

进入docker-compose源文件目录。cd /usr/local/src/docker-compose-aarch64
配置Dockerfile。vi Dockerfile更改如下:由于是直接在uos机器上编译,所以不需要进行交叉编译,注释掉RUN [ “cross-build-start” ]pip install时老是timeout,在此增加timeout时间, 配置清华源。
完整Dockerfile如下:

Go
# Dockerfile to build docker-compose for aarch64
FROM arm64v8/python:3.6.5-stretch

# Add env
ENV LANG C.UTF-8

# Enable cross-build for aarch64
COPY ./vendor/qemu-bin /usr/bin/
# RUN [ "cross-build-start" ]

# Set the versions
ENV DOCKER_COMPOSE_VER 1.22.0
# docker-compose requires pyinstaller 3.3.1 (check github.com/docker/compose/requirements-build.txt)
# If this changes, you may need to modify the version of "six" below
ENV PYINSTALLER_VER 3.3.1
# "six" is needed for PyInstaller. v1.11.0 is the latest as of PyInstaller 3.3.1
ENV SIX_VER 1.11.0

# Install dependencies
# RUN apt-get update && apt-get install -y
RUN pip install six==$SIX_VER

# Compile the pyinstaller "bootloader"
# https://pyinstaller.readthedocs.io/en/stable/bootloader-building.html
WORKDIR /build/pyinstallerbootloader
RUN curl -fsSL https://github.com/pyinstaller/pyinstaller/releases/download/v$PYINSTALLER_VER/PyInstaller-$PYINSTALLER_VER.tar.gz | tar xvz >/dev/null \
    && cd PyInstaller*/bootloader \
    && python3 ./waf all

# Clone docker-compose
WORKDIR /build/dockercompose
RUN git clone https://github.com/docker/compose.git . \
    && git checkout $DOCKER_COMPOSE_VER

# Run the build steps (taken from github.com/docker/compose/script/build/linux-entrypoint)
RUN mkdir ./dist \
    && pip install --default-timeout=1000 --no-cache-dir -q -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt -r requirements-build.txt \
    && ./script/build/write-git-sha \
    && pyinstaller docker-compose.spec \
    && mv dist/docker-compose ./docker-compose-$(uname -s)-$(uname -m)

# Disable cross-build for aarch64
# Note: don't disable this, since we want to run this container on x86_64, not aarch64
# RUN [ "cross-build-end" ]

# Copy out the generated binary
VOLUME /dist
CMD cp docker-compose-* /dist
# Dockerfile to build docker-compose for aarch64
FROM arm64v8/python:3.6.5-stretch

# Add env
ENV LANG C.UTF-8

# Enable cross-build for aarch64
COPY ./vendor/qemu-bin /usr/bin/
# RUN [ "cross-build-start" ]

# Set the versions
ENV DOCKER_COMPOSE_VER 1.22.0
# docker-compose requires pyinstaller 3.3.1 (check github.com/docker/compose/requirements-build.txt)
# If this changes, you may need to modify the version of "six" below
ENV PYINSTALLER_VER 3.3.1
# "six" is needed for PyInstaller. v1.11.0 is the latest as of PyInstaller 3.3.1
ENV SIX_VER 1.11.0

# Install dependencies
# RUN apt-get update && apt-get install -y
RUN pip install six==$SIX_VER

# Compile the pyinstaller "bootloader"
# https://pyinstaller.readthedocs.io/en/stable/bootloader-building.html
WORKDIR /build/pyinstallerbootloader
RUN curl -fsSL https://github.com/pyinstaller/pyinstaller/releases/download/v$PYINSTALLER_VER/PyInstaller-$PYINSTALLER_VER.tar.gz | tar xvz >/dev/null \
    && cd PyInstaller*/bootloader \
    && python3 ./waf all

# Clone docker-compose
WORKDIR /build/dockercompose
RUN git clone https://github.com/docker/compose.git . \
    && git checkout $DOCKER_COMPOSE_VER

# Run the build steps (taken from github.com/docker/compose/script/build/linux-entrypoint)
RUN mkdir ./dist \
    && pip install --default-timeout=1000 --no-cache-dir -q -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt -r requirements-build.txt \
    && ./script/build/write-git-sha \
    && pyinstaller docker-compose.spec \
    && mv dist/docker-compose ./docker-compose-$(uname -s)-$(uname -m)

# Disable cross-build for aarch64
# Note: don't disable this, since we want to run this container on x86_64, not aarch64
# RUN [ "cross-build-end" ]

# Copy out the generated binary
VOLUME /dist
CMD cp docker-compose-* /dist

安装docker-compose

cd /usr/local/src/docker-compose-aarch64
docker build . -t docker-compose-aarch64-builder
cd /usr/local/src/docker-compose-aarch64
docker build . -t docker-compose-aarch64-builder

运行和验证
运行docker-compose容器

(venv) root@uos-PC:/data/nfsdata/docker-compose-aarch64# docker run --rm -it docker-compose-aarch64-builder bash
root@6b31862b8797:/build/dockercompose# find / -name "docker-compose-Linux-aarch64"
/build/dockercompose/docker-compose-Linux-aarch64
root@6b31862b8797:/build/dockercompose# cd /build/dockercompose
root@6b31862b8797:/build/dockercompose# ./docker-compose-Linux-aarch64 --version
docker-compose version 1.22.0, build e20d808e
(venv) root@uos-PC:/data/nfsdata/docker-compose-aarch64# docker run --rm -it docker-compose-aarch64-builder bash
root@6b31862b8797:/build/dockercompose# find / -name "docker-compose-Linux-aarch64"
/build/dockercompose/docker-compose-Linux-aarch64
root@6b31862b8797:/build/dockercompose# cd /build/dockercompose
root@6b31862b8797:/build/dockercompose# ./docker-compose-Linux-aarch64 --version
docker-compose version 1.22.0, build e20d808e

最后从容器中拷贝docker-compose到宿主机上

docker cp e4b58853c83d:/build/dockercompose/docker-compose-Linux-aarch64 . 
docker cp e4b58853c83d:/build/dockercompose/docker-compose-Linux-aarch64 .

完。

文档更新时间: 2023-04-29 05:03   作者:阿力