背景: 在 CentOS
上用 Docker
部署遇到一些坑。
系統(tǒng)為 CentOS 7
, 升級(jí)了 pip(19)
后, 直接敲 pip install docker
安裝 Docker
。結(jié)果:
ImportError: cannot import name 'main'
上網(wǎng)搜索了大部分解決辦法都不行,可能環(huán)境和版本都有差異吧。
解決辦法
我的 macOS
的 pip
是沒問題的啊,于是:more /usr/local/lib/python3.7/site-packages/pip/__main__.py
from __future__ import absolute_import
import os
import sys
# If we are running from a wheel, add the wheel to sys.path
# This allows the usage python pip-*.whl/pip install pip-*.whl
if __package__ == '':
# __file__ is pip-*.whl/pip/__main__.py
# first dirname call strips of '/__main__.py', second strips off '/pip'
# Resulting path is the name of the wheel itself
# Add that to sys.path so we can import pip
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)
from pip._internal import main as _main # isort:skip # noqa
if __name__ == '__main__':
sys.exit(_main())
答案很明顯了。
然后開心的裝了 docker(Docker version 1.13.1)
和 docker-compose(docker-compose version 1.24.1)
后,準(zhǔn)備 docker-compose up -d
然后又出問題:
Creating wechat_auto_reply_web_1 ... done
Attaching to wechat_auto_reply_web_1
web_1 | python: can't open file './auto_reply.py': [Errno 13] Permission denied
wechat_auto_reply_web_1 exited with code 2
在加了權(quán)限和嘗試各種方法后,解決辦法
-
SELinux
的原因,執(zhí)行setenforce 0
就可以了(原因可以去了解一下) -
docker
添加--privileged
參數(shù)。我采取了此辦法,在docker-compose.yml
添加privileged: true
參考于: https://nanxiao.me/en/selinux-cause-permission-denied-issue-in-using-docker/
以上,問題都解決了。