为什么在 ubuntu 上运行 docker-compose 时出现权限被拒绝错误?

为什么在 ubuntu 上运行 docker-compose 时出现权限被拒绝错误?

我已经在我的笔记本电脑上安装了全新的 kubuntu 22.04,当我尝试安装 docker 时,我已经安装了 docker-ce 和 docker-compose:

root@serge-at-home:/mnt/_work_sdb8/wwwroot/lar/MngProducts# dpkg -s   docker-compose
Package: docker-compose
Status: install ok installed
Priority: optional
Section: admin
Installed-Size: 498
Maintainer: Ubuntu Developers <[email protected]>
Architecture: all
Version: 1.29.2-1
Depends: python3-cached-property (>= 1.2.0) | python3 (>> 3.8), python3-distro (>= 1.5.0), python3-docker (>= 5), python3-dockerpty (>= 0.4.1), python3-docopt (>= 0.6.1), python3-dotenv (>= 0.13.0), python3-jsonschema, python3-requests (>= 2.20.0), python3-texttable (>= 0.9.0), python3-websocket (>= 0.32.0), python3-yaml (>= 3.10), python3:any, python3-distutils
Recommends: docker.io (>= 1.9.0)
Description: define and run multi-container Docker applications with YAML
docker-compose is a service management software built on top of docker. Define
your services and their relationships in a simple YAML file, and let compose
handle the rest.
Original-Maintainer: Docker Compose Team <[email protected]>
Homepage: https://docs.docker.com/compose/
root@serge-at-home:/mnt/_work_sdb8/wwwroot/lar/MngProducts# dpkg -s   docker-ce
Package: docker-ce
Status: install ok installed
Priority: optional
Section: admin
Installed-Size: 94347
Maintainer: Docker <[email protected]>
Architecture: amd64
Version: 5:24.0.6-1~ubuntu.22.04~jammy
Replaces: docker-engine
Depends: containerd.io (>= 1.6.4), docker-ce-cli, iptables, libseccomp2 (>= 2.3.0), libc6 (>= 2.34), libdevmapper1.02.1 (>= 2:1.02.97), libsystemd0
Recommends: apparmor, ca-certificates, docker-ce-rootless-extras, git, libltdl7, pigz, procps, xz-utils
Suggests: aufs-tools, cgroupfs-mount | cgroup-lite
Conflicts: docker (<< 1.5~), docker-engine, docker-engine-cs, docker.io, lxc-docker, lxc-docker-virtual-package
Conffiles:
/etc/default/docker 01f06689327cb8ded58332709d28670c
/etc/init.d/docker 4cd80dac70f6019cb5a9c36c38f2e8d2
Description: Docker: the open-source application container engine
Docker is a product for you to build, ship and run any application as a
lightweight container
.
Docker containers are both hardware-agnostic and platform-agnostic. This means
they can run anywhere, from your laptop to the largest cloud compute instance and
everything in between - and they don't require you to use a particular
language, framework or packaging system. That makes them great building blocks
for deploying and scaling web apps, databases, and backend services without
depending on a particular stack or provider.
Homepage: https://www.docker.com

root@serge-at-home:/mnt/_work_sdb8/wwwroot/lar/MngProducts# uname -a
Linux serge-at-home 6.2.0-34-generic #34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep  7 13:12:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

我已经运行命令:

sudo chmod +x /usr/bin/docker-compose

没有错误。
但在我的项目上运行docker时,我还是得到了“权限被拒绝”的错误

serge@serge-at-home:/_wwwroot/lar/FilamentBanners/__DOCKER$ docker-compose up -d --build
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.10/http/client.py", line 1283, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 976, in send
self.connect()
File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect
sock.connect(self.unix_socket)
PermissionError: [Errno 13] Permission denied

我还运行命令:

usermod -aG docker $USER 

newgrp - docke

但无论如何都是同样的错误...我在安装过程中错过了什么?

答案1

您正在运行旧版 Docker Compose(docker-compose),它不再开发(并且也不再包含在 Docker 存储库中)。

我建议切换到新的 Docker Compose V2 插件(docker compose),而不是对不受支持的软件进行故障排除。

首先删除旧软件包:(来自 Ubuntu 存储库,与您的 Docker 版本不匹配)

sudo apt-get remove docker-compose

现在安装新版本:(来自 Docker repos)

sudo apt-get install docker-compose-plugin

从现在开始,不要使用docker-composedocker compose而是使用 - 也看这里用于创建别名。

相关内容