ubuntu上安装docker-compose踩坑记录

报错如下:

$ docker-compose up 
/usr/local/lib/python3.8/dist-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (2.2.0) or chardet (3.0.4)/charset_normalizer (2.0.12) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 8, in 
    sys.exit(main())
  File "/home/local/EUROPRO/pca_yanyan/.local/lib/python3.8/site-packages/compose/cli/main.py", line 81, in main
    command_func()
  File "/home/local/EUROPRO/pca_yanyan/.local/lib/python3.8/site-packages/compose/cli/main.py", line 200, in perform_command
    project = project_from_options('.', options)
  File "/home/local/EUROPRO/pca_yanyan/.local/lib/python3.8/site-packages/compose/cli/command.py", line 60, in project_from_options
    return get_project(
  File "/home/local/EUROPRO/pca_yanyan/.local/lib/python3.8/site-packages/compose/cli/command.py", line 152, in get_project
    client = get_client(
  File "/home/local/EUROPRO/pca_yanyan/.local/lib/python3.8/site-packages/compose/cli/docker_client.py", line 41, in get_client
    client = docker_client(
  File "/home/local/EUROPRO/pca_yanyan/.local/lib/python3.8/site-packages/compose/cli/docker_client.py", line 124, in docker_client
    kwargs = kwargs_from_env(environment=environment, ssl_version=tls_version)
TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'

这个报错有两个点需要解决的:

1. 错误1是:

/usr/local/lib/python3.8/dist-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (2.2.0) or chardet (3.0.4)/charset_normalizer (2.0.12) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "

我的docker是用的sudo安装的,而docker-compose是虚拟环境内安装的.通过whereis docker-compose 查看路径,只在/usr/local/bin/docker-compose目录下生成,而 /usr/bin/docker-compose没有
cp命令将docker-compose复制过去就可以了

$ whereis docker-compose
docker-compose: /usr/local/bin/docker-compose /home/local/EUROPRO/pca_yy/.myvirtualenv/py38/bin/docker-compose
$ sudo cat /etc/sudoers
[sudo] EUROPRO\pca_yanyan 的密码: 
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root	ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL
EUROPRO\\PCASudoers ALL=(ALL) ALL
zyy ALL=(ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
EUROPRO\\pca_zyy ALL=(ALL) ALL

执行一下这句

$ sudo cp -r /usr/local/bin/docker-compose /usr/bin/docker-compose

 2.错误2是:

是urllib3 chardet 的版本不一致造成的

$ docker-compose --version
/usr/local/lib/python3.8/dist-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (2.2.0) or chardet (3.0.4)/charset_normalizer (2.0.12) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
docker-compose version 1.29.2, build unknown

sudo pip3 uninstall urllib3 chardet

sudo pip3 install --upgrade requests

 用sudo方式执行上面红色的两行命令,切换依赖的版本后,顺利解决,看下:

$ sudo docker-compose --version
docker-compose version 1.29.2, build unknown
3.结果build的时候还报了错:
$ sudo docker-compose up --build
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 8, in 
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/compose/cli/main.py", line 81, in main
    command_func()
  File "/usr/local/lib/python3.8/dist-packages/compose/cli/main.py", line 200, in perform_command
    project = project_from_options('.', options)
  File "/usr/local/lib/python3.8/dist-packages/compose/cli/command.py", line 60, in project_from_options
    return get_project(
  File "/usr/local/lib/python3.8/dist-packages/compose/cli/command.py", line 152, in get_project
    client = get_client(
  File "/usr/local/lib/python3.8/dist-packages/compose/cli/docker_client.py", line 41, in get_client
    client = docker_client(
  File "/usr/local/lib/python3.8/dist-packages/compose/cli/docker_client.py", line 124, in docker_client
    kwargs = kwargs_from_env(environment=environment, ssl_version=tls_version)
TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'
执行以下命令

$ sudo pip3 install pyyaml==5.3.1

$ sudo pip3 install docker

$ sudo pip3 install docker-compose

最后用最简单的flaskdemo验证一下,浏览器访问 http://127.0.0.1:5000正常  完美解决!

$ sudo docker-compose up --build
/usr/local/lib/python3.5/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release of cryptography. Please upgrade your Python.
  from cryptography.hazmat.backends import default_backend
Building web
[+] Building 4.7s (9/9) FINISHED                                                                                                                                                            docker:default
 => [internal] load build definition from dockerfile                                                                                                                                                  0.0s
 => => transferring dockerfile: 159B                                                                                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/python:3.5                                                                                                                                         0.0s
 => [internal] load .dockerignore                                                                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                                                                       0.0s
 => [1/4] FROM docker.io/library/python:3.5                                                                                                                                                           0.0s
 => [internal] load build context                                                                                                                                                                     0.0s
 => => transferring context: 564B                                                                                                                                                                     0.0s
 => CACHED [2/4] RUN apt-get -y update                                                                                                                                                                0.0s
 => [3/4] COPY . .                                                                                                                                                                                    0.0s
 => [4/4] RUN pip3 install -r requirements.txt                                                                                                                                                        4.5s
 => exporting to image                                                                                                                                                                                0.1s
 => => exporting layers                                                                                                                                                                               0.1s
 => => writing image sha256:fbbfa0243e8dcde522e5e2defb0f3eb986bcd077e0695e343ba0e17626df2b32                                                                                                          0.0s 
 => => naming to docker.io/library/application_web                                                                                                                                                    0.0s 
Successfully built fbbfa0243e8dcde522e5e2defb0f3eb986bcd077e0695e343ba0e17626df2b32                                                                                                                        
Recreating application_web_1 ... done
Attaching to application_web_1
web_1  |  * Serving Flask app "app" (lazy loading)
web_1  |  * Environment: production
web_1  |    WARNING: This is a development server. Do not use it in a production deployment.
web_1  |    Use a production WSGI server instead.
web_1  |  * Debug mode: on
web_1  |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
web_1  |  * Restarting with stat
web_1  |  * Debugger is active!
web_1  |  * Debugger PIN: 245-125-106
web_1  | 172.18.0.1 - - [05/Feb/2024 05:30:08] "GET / HTTP/1.1" 200 -
web_1  | 172.18.0.1 - - [05/Feb/2024 05:30:08] "GET /favicon.ico HTTP/1.1" 404 -
^Z
[6]+  已停止               sudo docker-compose up --build

补充:

flask验证代码如下:

层级

application (此文件夹是项目根目录)

        docker-compose.yml   (application的子文件)

        web (此文件夹是application的子文件夹)

                app.py  dockerfile  requirements.txt (web的子文件)

$ mkdir application

$ cd application

application$ mkdir web

application$ cd web

application/web$  vi app.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def nhooo():
    return "Welcome to nhooo"

if __name__ == '__main__':
#call the run method
    app.run(debug=True,host='0.0.0.0')

application/web$ vi dockerfile  (提示:此处python:3.5镜像可能需要自己去拉取 sudo docker pull python:3.5)

FROM python:3.5
RUN apt-get -y update
COPY . .
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3"]
CMD ["app.py"]

application/web$ vi requirements.txt

flask

application/web$ cd ..

application$ vi docker-compose.yml

version: '3'
 
services:
  web:
    build: ./web
    ports:
            - "5000:5000"

写好了之后,sudo docker-compose up --build 启动。

 

 

你可能感兴趣的:(ubuntu,docker)