起因
树莓派里 apt 下载的 docker-compose 最新版也只是 1.8.2 版本
奈何执行 docker-compose.yaml 文件又是 version: "3" 版本的
猜测之所以能升成功,有一种巧合在里面,我是不小心把python2.7 给删了,又安装上了,但 /usr/bin/python 用的是3.5版本的
解决
官方安装脚本为
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
但是在树莓派 3B+ 上,如果执行echo命令查看此链接地址
echo "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)"
结果
https://github.com/docker/compose/releases/download/1.25.4/docker-compose-Linux-armv7l
意思官方并没有发布 ARM 架构的 docker-compose 安装文件,所以此方法行不通,现在采用 pip 来安装
使用 pip 安装 docker-compose
1.apt更新
sudo apt-get update
2.安装python和pip
sudo apt-get install -y python python-pip
3.安装libffi-dev
sudo apt-get install libffi-dev
可能会出现的错误:如果不安装 libffi-dev 的话,后面使用 pip 安装 docker-compose 的时候会报错,提示找不到 ffi.h 文件
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-armv7l-2.7/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
4.用pip安装docker-compose
sudo pip install docker-compose
5.拷贝python2.7的dist-packages文件夹到docker的工作目录下
cd /usr/local/lib/python2.7/dist-packages
sudo cp -r backports /usr/local/lib/python2.7/dist-packages/docker/transport/
如果不执行此操作,使用 docker-compose 命令会报错:No module named ssl_match_hostname
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 5, in <module>
from compose.cli.main import main
File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 18, in <module>
import docker.errors
File "/usr/local/lib/python2.7/dist-packages/docker/__init__.py", line 2, in <module>
from .api import APIClient
File "/usr/local/lib/python2.7/dist-packages/docker/api/__init__.py", line 2, in <module>
from .client import APIClient
File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 10, in <module>
from .build import BuildApiMixin
File "/usr/local/lib/python2.7/dist-packages/docker/api/build.py", line 6, in <module>
from .. import auth
File "/usr/local/lib/python2.7/dist-packages/docker/auth.py", line 9, in <module>
from .utils import config
File "/usr/local/lib/python2.7/dist-packages/docker/utils/__init__.py", line 3, in <module>
from .decorators import check_resource, minimum_version, update_headers
File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 4, in <module>
from . import utils
File "/usr/local/lib/python2.7/dist-packages/docker/utils/utils.py", line 13, in <module>
from .. import tls
File "/usr/local/lib/python2.7/dist-packages/docker/tls.py", line 5, in <module>
from .transport import SSLHTTPAdapter
File "/usr/local/lib/python2.7/dist-packages/docker/transport/__init__.py", line 3, in <module>
from .ssladapter import SSLHTTPAdapter
File "/usr/local/lib/python2.7/dist-packages/docker/transport/ssladapter.py", line 23, in <module>
from backports.ssl_match_hostname import match_hostname
ImportError: No module named ssl_match_hostname
6.安装完毕
执行一次docker-compose命令测试是否安装成功
docker-compose version
安装成功则能成功打印版本号信息。
如果报错 No module named shutil_get_terminal_size
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 5, in <module>
from compose.cli.main import main
File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 52, in <module>
from .formatter import ConsoleWarningFormatter
File "/usr/local/lib/python2.7/dist-packages/compose/cli/formatter.py", line 15, in <module>
from backports.shutil_get_terminal_size import get_terminal_size
ImportError: No module named shutil_get_terminal_size
那么安装一下ipython
sudo apt-get install ipython
安装完后再次执行docker-compose命令就没问题
pi@raspberrypi:/var/lib/dpkg $ docker-compose version
docker-compose version 1.28.2, build unknown
docker-py version: 4.4.1
CPython version: 3.5.3
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
参考:
E: Sub-process /usr/bin/dpkg returned an error cod
树莓派4b安装Docker与docker-compose过程及问题解决
arm服务器安装docker及docker-compose
编译arm 版本docker-compose
来源:oschina
链接:https://my.oschina.net/u/4359458/blog/4940165