美文网首页
树莓派4b安装Docker与docker-compose过程及问

树莓派4b安装Docker与docker-compose过程及问

作者: lancely | 来源:发表于2020-03-12 09:41 被阅读0次

    安装 Docker

    安装Docker可使用官方脚本一键安装

    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    

    如果安装过程过慢,可以参考解决树莓派apt-get更新速度慢的方法

    安装 Docker Compose

    官方安装脚本为

    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
    

    但是在树莓派4b上,如果执行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命令就没问题

    docker-compose version 1.25.4, build unknown
    docker-py version: 4.2.0
    CPython version: 2.7.16
    OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019
    

    相关文章

      网友评论

          本文标题:树莓派4b安装Docker与docker-compose过程及问

          本文链接:https://www.haomeiwen.com/subject/yqfyjhtx.html