简介
继上篇安装docker容器后,本文继续安装docker-compose。
docker-compose可以从官网下载
https://github.com/docker/compose/releases
但是遗憾的是,目前官网没有提供ARM版本的,所以只能自行编译。
环境准备
1,操作系统 Kylin 麒麟 aarch64
2,docker ARM版本
3,git工具
编译
我们直接使用docker-compose-aarch64仓库脚本进行编译,该脚本使用docker容器环境进行编译,这样就不会对本机环境造成任何影响(洁癖人员点赞)。
克隆仓库
git clone https://github.com/ubiquiti/docker-compose-aarch64.git
进入目录docker-compose-aarch64
cd docker-compose-aarch64
打开Dockerfile并进行修改
由于是直接在ARM服务器机器上编译,所以不需要进行交叉编译,注释掉RUN [ “cross-build-start” ]
增加pip install timeout时间,同时配置清华源加快下载速度。
最终修改好的Dockerfile如下
# 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 build . -t docker-compose-aarch64-builder
运行镜像,得到编译的docker-compose
注意:/home/tickstep/docker-compose-aarch64-master 这个目录要换成你自己本机的目录,当编译完成后,docker-compose文件会存储在这个目录下面
docker run --rm -v /home/tickstep/docker-compose-aarch64-master:/dist docker-compose-aarch64-builder
编译成功得到docker-compose二进制执行文件
安装docker-compose
依次执行以下命令
cp docker-compose-Linux-aarch64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
验证
[root@Kylin /]# docker-compose -v
docker-compose version 1.22.0, build e20d808e
清理
已经完成编译并安装,之前编译的docker镜像已经不再需要,可以删除
docker rmi docker-compose-aarch64-builder