Docker Stack任务由于权限被拒绝错误而被拒绝

时间:2018-10-27 15:59:48

标签: docker docker-compose docker-stack docker-network

我尝试使用docker stack deploy命令部署堆栈(包含一项服务),并在我的应用程序上成群运行2个实例!这是我的docker-compose文件:

version: "3"
services:
  server:
    image: makbn/thumbnailer-server:v1
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
      resources:
        limits:
          cpus: "0.1"
          memory: 1024M
      restart_policy:
        condition: on-failure
    ports:
      - 8080:8080
    networks: 
      - server_network
networks: 
  server_network:

运行sudo docker stack deploy -c ./docker-compose.yml ts命令后,我的堆栈已成功部署到群集,但这是我的docker stack ps ts输出:

ID                  NAME                IMAGE                         NODE                DESIRED STATE       CURRENT STATE             ERROR                              PORTS
8zmjp6wt47ki        ts_server.1         makbn/thumbnailer-server:v1   fanap9-lp           Ready               Rejected 2 seconds ago    "mkdir /var/lib/docker: permis…"   
88vizpnabbi8         \_ ts_server.1     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 7 seconds ago    "mkdir /var/lib/docker: permis…"   
609hl7hy7tnu         \_ ts_server.1     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 12 seconds ago   "mkdir /var/lib/docker: permis…"   
gif8fvbgdhpy         \_ ts_server.1     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 17 seconds ago   "mkdir /var/lib/docker: permis…"   
x60x9c6albe5         \_ ts_server.1     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 22 seconds ago   "mkdir /var/lib/docker: permis…"   
ugvbw1gpdp8e        ts_server.2         makbn/thumbnailer-server:v1   fanap9-lp           Ready               Rejected 2 seconds ago    "mkdir /var/lib/docker: permis…"   
p34x1kp55ch8         \_ ts_server.2     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 7 seconds ago    "mkdir /var/lib/docker: permis…"   
3exxflukrl4y         \_ ts_server.2     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 12 seconds ago   "mkdir /var/lib/docker: permis…"   
ud83xfj5nefj         \_ ts_server.2     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 17 seconds ago   "mkdir /var/lib/docker: permis…"   
ws35na8up793         \_ ts_server.2     makbn/thumbnailer-server:v1   fanap9-lp           Shutdown            Rejected 22 seconds ago   "mkdir /var/lib/docker: permis…"   

完整的错误消息是 mkdir / var / lib / docker:权限被拒绝

另一个问题是,当我尝试使用已部署并成功运行的docker service create命令服务来创建堆栈时,却无法从本地主机访问该服务!我有2个问题:

  1. 从撰写文件部署堆栈有什么问题,为什么我会收到 mkdir / var / lib / docker:权限被拒绝错误?
  2. 如何将我的服务网络配置为可从主机访问?

2 个答案:

答案 0 :(得分:3)

(注意:仅与可能通过snap安装了docker的用户有关)

我遇到了这个问题,因为我安装了snap码头工人,这意味着docker-compose对我的码头工人安装感到困惑。 /var/lib/docker给出了文件权限错误,因为我的系统实际上在/snap/bin/docker上使用了docker

要检查是否适合您,可以运行which docker。如果返回/usr/bin/docker,则说明您已完成常规应用的安装。

如果它在路径/snap/返回某内容,则意味着您已经从snap docker软件包安装(不再维护。参考:https://github.com/docker/docker-snap

为解决此问题,我首先使用snap remove docker卸载了snap docker install,然后按照https://docs.docker.com/install/linux/docker-ce/ubuntu/#docker-ee-customers上的docker设置说明进行了安装。一旦这样做,我就可以毫无问题地部署堆栈。

我不记得要怎么快速安装docker了,但是通过设置存储库然后运行sudo apt install docker.io来安装似乎是可行的方法。

答案 1 :(得分:0)

我在几个小时之前对这个问题进行了故障排除,由于相同的“拒绝权限”错误,容器将显示为被拒绝并关闭。我还拥有能够手动创建和扩展服务的上下文,但是无法与.yml取得相同的结果。

getting started guide之后,在他们的docker-compose.yml示例中,他们使用version: "3",但并没有继续说应该与您的相应Compose File Format编号匹配。根据安装的Docker版本,我的编号最终为“ 3.7”,因此在docker-compose.yml中对其进行更改后,相应地,我的容器能够通过docker stack deploy -c docker-compose.yml some-name进行复制。

撰写文件格式(CFF):Docker引擎版本(DCR)

CFF     DCR
3.7     18.06.0+
3.6     18.02.0+
3.5     17.12.0+
3.4     17.09.0+
3.3     17.06.0+
3.2     17.04.0+
3.1     1.13.1+
3.0     1.13.0+
2.4     17.12.0+
2.3     17.06.0+
2.2     1.13.0+
2.1     1.12.0+
2.0     1.10.0+
1.0     1.9.1.+

提供参考文档(here

无效到有效更改的示例

# From the Example
version: "3"
services:
  web:
    image: username/repo:tag

# What's actually required (in my case, because I'm using docker version 18.09.2)
version: "3.7"
services:
  web:
    image: username/repo:tag

更改后的结果

owner@test_server:~/myyml$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                               PORTS
baxip2g6xgzy        first-swarm_web     replicated          5/5                 [username]/getting-started:my-serv   *:4000->80/tcp

owner@test_server:~/myyml$ docker service ps first-swarm_web
ID                  NAME                IMAGE                               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
ss6jn07htkhp        first-swarm_web.1   [username]/getting-started:my-serv   test_server         Running             Running 37 minutes ago                       
n5eael5ae3jl        first-swarm_web.2   [username]/getting-started:my-serv   test_server         Running             Running 37 minutes ago                       
kzb3l1hzdpet        first-swarm_web.3   [username]/getting-started:my-serv   test_server         Running             Running 37 minutes ago                       
6ijgoebvhhdg        first-swarm_web.4   [username]/getting-started:my-serv   test_server         Running             Running 37 minutes ago                       
h0mbz1fp1id6        first-swarm_web.5   [username]/getting-started:my-serv   test_server         Running             Running 37 minutes ago