docker-compose 安装以及遇到的错误解决

今天在编译一个docker项目到时候,遇到了很多问题。记录一下

架构:Python+Django+bootstrap+SaltStack+Zabbix+MySQL

1 bash: docker-compose: command not found...

[root@localhost mysite]# docker-compose build
bash: docker-compose: command not found...
[root@localhost mysite]# pip -V
bash: pip: command not found...
[root@localhost opt]# pip -V
pip 20.1.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
[root@localhost opt]# pip install docker-compose
ERROR: jsonschema 3.2.0 has requirement six>=1.11.0, but you'll have six 1.9.0 which is incompatible.
[root@localhost mysite]# pip install six --user -U
ImportError: No module named configparser

很多关于configparser,说是python 3.x修改了名字

[root@localhost mysite]# pip uninstall docker-compose
[root@localhost mysite]# pip install docker-compose
[root@localhost mysite]# docker-compose --version
[root@localhost mysite]# find / -name docker-compose
/usr/bin/docker-compose
[root@localhost mysite]# docker-compose --version
Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 5, in <module>
    from compose.cli.main import main
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 24, in <module>
    from ..config import ConfigurationError
  File "/usr/lib/python2.7/site-packages/compose/config/__init__.py", line 6, in <module>
    from .config import ConfigurationError
  File "/usr/lib/python2.7/site-packages/compose/config/config.py", line 51, in <module>
    from .validation import match_named_volumes
  File "/usr/lib/python2.7/site-packages/compose/config/validation.py", line 12, in <module>
    from jsonschema import Draft4Validator
  File "/usr/lib/python2.7/site-packages/jsonschema/__init__.py", line 33, in <module>
    import importlib_metadata as metadata
  File "/usr/lib/python2.7/site-packages/importlib_metadata/__init__.py", line 16, in <module>
    from ._compat import (
  File "/usr/lib/python2.7/site-packages/importlib_metadata/_compat.py", line 20, in <module>
    from backports.configparser import ConfigParser
ImportError: No module named configparser
[root@localhost mysite]# find / -name docker-compose
/usr/bin/docker-compose
[root@localhost mysite]# find / -name ConfigParser
[root@localhost mysite]# find / -name configparser
[root@localhost mysite]# python -V
Python 2.7.5
[root@localhost mysite]# python -c 'import six; print(six.__version__)'
1.15.0
[root@localhost mysite]# python -c 'import six.moves; print(dir(six.moves))'
--pip install --user pytz requests tqdm tzlocal python-dateutil
--pip install configparser

还是不行,于是把python2换成python3.6试试

[root@localhost Python-3.6.0]# ./configure --enable-shared --prefix=/usr/local/python36/
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/opt/Python-3.6.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@localhost Python-3.6.0]# yum install gcc -y
[root@localhost Python-3.6.0]# make && make install
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
[root@localhost Python-3.6.0]# yum -y install zlib*
再次运行make && make install 即可
[root@localhost ~]# which python
/usr/bin/python
[root@localhost ~]# ll /usr/bin/python*
lrwxrwxrwx. 1 root root    7 Jul 16 22:00 /usr/bin/python -> python2
lrwxrwxrwx. 1 root root    9 Jul 16 22:00 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Aug  3  2017 /usr/bin/python2.7
[root@localhost ~]# rm /usr/bin/python
[root@localhost ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python
[root@localhost ~]# python -V
python: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
[root@localhost ~]# ll /usr/local/python36/lib/libpython3.6m.so.1.0 
-r-xr-xr-x. 1 root root 12331440 Jul 17 03:19 /usr/local/python36/lib/libpython3.6m.so.1.0
[root@localhost ~]# cp /usr/local/python36/lib/libpython3.6m.so.1.0 /usr/lib64/
[root@localhost ~]# python -V
Python 3.6.0
[root@localhost opt]# pip --version
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'
[root@localhost opt]# pip install -U pip //sudo easy_install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'
[root@localhost opt]# which pip
/usr/bin/pip
[root@localhost opt]# vim /usr/bin/yum
将第一行"#!/usr/bin/python" 改为 "#!/usr/bin/python2"即可
[root@localhost opt]# yum install  python3-pip
Downloading packages:
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
[root@localhost opt]# vim /usr/libexec/urlgrabber-ext-down
将第一行"#!/usr/bin/python" 改为 "#!/usr/bin/python2"即可    
[root@localhost opt]# ll /usr/bin/pip*
-rwxr-xr-x. 1 root root 220 Jul 17 02:14 /usr/bin/pip
-rwxr-xr-x. 1 root root 220 Jul 17 02:14 /usr/bin/pip2
-rwxr-xr-x. 1 root root 220 Jul 17 02:14 /usr/bin/pip2.7
[root@localhost opt]# yum install  python3-pip -y
[root@localhost opt]# ll /usr/bin/pip*
-rwxr-xr-x. 1 root root 220 Jul 17 02:14 /usr/bin/pip
-rwxr-xr-x. 1 root root 220 Jul 17 02:14 /usr/bin/pip2
-rwxr-xr-x. 1 root root 220 Jul 17 02:14 /usr/bin/pip2.7
-rwxr-xr-x. 1 root root 407 Mar 17 19:38 /usr/bin/pip3
lrwxrwxrwx. 1 root root   9 Jul 17 03:35 /usr/bin/pip-3 -> ./pip-3.6
lrwxrwxrwx. 1 root root   8 Jul 17 03:35 /usr/bin/pip-3.6 -> ./pip3.6
-rwxr-xr-x. 1 root root 407 Mar 17 19:38 /usr/bin/pip3.6
[root@localhost opt]# pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

安装docker-compose

方法1(在线安装,网络问题)
# yum -y install libcurl libcurl-devel
# curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# docker-compose --version

方法2 
安装python-pip
yum -y install epel-release
yum -y install python-pip
安装docker-compose
pip install docker-compose
pip install -U docker-compose==1.23.2

方法3 离线安装
https://github.com/docker/compose/releases/tag/1.23.2
下载安装包docker-compose-Linux-x86_64
[root@localhost opt]# mv docker-compose-Linux-x86_64  /usr/local/bin/docker-compose
mv: overwrite ‘/usr/local/bin/docker-compose’? y
[root@localhost opt]# chmod +x /usr/local/bin/docker-compose
[root@localhost opt]# docker-compose --version
Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 5, in <module>
    from compose.cli.main import main
ModuleNotFoundError: No module named 'compose'

问题依旧:

以使用国内的pip源进行加速
[root@localhost opt]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -U docker-compose
[root@localhost opt]# docker-compose --version
docker-compose version 1.26.2, build unknown
[root@localhost mysite]# docker-compose build
pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out.
You are using pip version 9.0.1, however version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt' returned a non-zero code: 2
修改文件/mysite/Dockerfile
把pip修改为pip3
pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out.
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt' returned a non-zero code: 2
[root@localhost mysite]# pip3 --default-timeout=100 install -U pip
[root@localhost mysite]# docker-compose build ##执行成功
[root@localhost mysite]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysite_web          latest              8f76bc36af1b        7 minutes ago       867 MB
docker.io/mysql     latest              6e447ce4863d        3 days ago          544 MB
docker.io/python    3.6.0               a1782fa44ef7        3 years ago         687 MB
docker.io/django    1.9.5               c5b6e7c5c44c        4 years ago         433 MB
[root@localhost mysite]# docker-compose run web django-admin.py startproject webserver ./DjangoWeb
Creating mysite_db_1 ... done
    with open(new_path, 'wb') as new_file:
PermissionError: [Errno 13] Permission denied: '/code/DjangoWeb/manage.py' ###The problem was with SELinux enabled on centos 7.

[root@localhost DjangoWeb]# vim /etc/selinux/config
[root@localhost DjangoWeb]# getenforce
Enforcing
[root@localhost DjangoWeb]# setenforce 0
[root@localhost DjangoWeb]# getenforce
Permissive
[root@localhost DjangoWeb]# docker-compose run web django-admin.py startproject webserver ./DjangoWeb
Starting mysite_db_1 ... done
[root@localhost DjangoWeb]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                          PORTS                 NAMES
402e7e3c3a51        mysite_web          "django-admin.py s..."   About a minute ago   Exited (0) About a minute ago                         mysite_web_run_1155b6d3892c
429d164feb1f        mysite_web          "django-admin.py s..."   5 minutes ago        Exited (1) 5 minutes ago                              mysite_web_run_b00ff320f226
0f7ed906ee56        mysite_web          "django-admin.py s..."   6 minutes ago        Exited (1) 6 minutes ago                              mysite_web_run_4d1a59a80e82
afed01a08c0a        mysite_web          "django-admin.py s..."   15 minutes ago       Exited (1) 15 minutes ago                             mysite_web_run_6ac17fcdc847
436c584720a5        mysql               "docker-entrypoint..."   15 minutes ago       Up About a minute               3306/tcp, 33060/tcp   mysite_db_1
7dd3c70e6dad        21dceb2c4044        "/bin/sh -c 'pip3 ..."   33 minutes ago       Exited (2) 31 minutes ago                             trusting_goldberg
a228801885f4        21dceb2c4044        "/bin/sh -c 'pip i..."   37 minutes ago       Exited (2) 36 minutes ago                             keen_mcnulty
posted @ 2020-07-17 17:16  春困秋乏夏打盹  阅读(13907)  评论(0编辑  收藏  举报