解决:E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)

简介: 为了让容器服务启动更加方面,于是自己手写了一个 docker-compose.yml 配置脚本。脚本内容如下:

目录

  • 问题
  • 解决
  • 结尾

问题

为了让容器服务启动更加方面,于是自己手写了一个 docker-compose.yml 配置脚本。脚本内容如下:

version: '3'
services:
  fake-sqs:
    image: registry.cn-beijing.aliyuncs.com/liuzhen007/sqs-x86:1.0.6.1
    container_name: fake-sqs
    restart: always
    network_mode: "host"

完成后启动服务,服务也运行正常,没有报错。自己运行如下命令进入容器查看 docker 运行状况:

docker exec -it  81402e58e15e bash

查看服务端口监听状态,命令如下:

docker@al-bj-boom-hb-backstage-01:/$ netstat -an | grep 4566 bash: netstat: command not found

提示没有工具命令 netstat,于是执行如下命令安装:

apt-get install net-tools

此时,却发生了如下报错信息:

docker@al-bj-boom-hb-backstage-01:/$ apt-get install net-tools

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)

E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

解决

网上搜索解决方案时,有一种说法是删除提示的文件:/var/lib/dpkg/lock,感觉不是很靠谱,自己觉得是别的原因导致的。

很可能是自己写的 docker-compose.yml 配置脚本有问题,于是自己顺着方向查下去,果然最后让自己发现了一个配置参数 user: root 。瞬间,自己就知道哪里出错误了,于是修改 docker-compose.yml 配置脚本,修改后内容如下:

version: '3'
services:
  fake-sqs:
    image: registry.cn-beijing.aliyuncs.com/liuzhen007/sqs-x86:1.0.6.1
    container_name: fake-sqs
    restart: always
    network_mode: "host"
    user: root

然后重新启动服务,再执行刚才的命令,问题解决。

结尾

自己对 docker-compose 的使用不是很了解,因此出现了这样的基础错误。其实,实际开发中遇到的很多问题,最终定位都有可能是非常小的点。你遇到哪些非常简单的错误呢?欢迎评论。


作者简介:大家好,我是 Data-Mining(liuzhen007),是一位典型的音视频技术爱好者,同时也是CSDN博客专家、华为云享专家(共创编辑)、InfoQ 签约作者,欢迎关注我分享更多干货!

目录
相关文章
|
12月前
libfreetype.so.6: cannot open shared object file: No such file or directory
libfreetype.so.6: cannot open shared object file: No such file or directory
462 0
|
机器学习/深度学习 Linux
解决ImportError libgmpxx.so.4 cannot open shared object file No such file or directory
解决ImportError libgmpxx.so.4 cannot open shared object file No such file or directory
216 0
解决ImportError libgmpxx.so.4 cannot open shared object file No such file or directory
|
6月前
|
缓存 Ubuntu Linux
error while loading shared libraries: libxcb-icccm.so.4: cannot open shared object file: No such file or directory 问题如何处理
【5月更文挑战第16天】error while loading shared libraries: libxcb-icccm.so.4: cannot open shared object file: No such file or directory 问题如何处理
751 0
|
6月前
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
|
12月前
|
缓存 Ubuntu Linux
错误 E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
错误 E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su
gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su
184 0
|
并行计算 TensorFlow 算法框架/工具
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
290 0
|
开发工具 git
error: could not lock config file .git/config: Permission denied/Command failed with exit 255
error: could not lock config file .git/config: Permission denied/Command failed with exit 255
388 0