gpt4 book ai didi

python - Dockerfile没有安装python-dotenv库

转载 作者:行者123 更新时间:2023-12-02 20:52:43 25 4
gpt4 key购买 nike

我的Dockerfile:

FROM python:3.9

WORKDIR /usr/src/app

RUN pip install python-dotenv
RUN pip install other_libraries...
在构建容器期间,显示消息:
...
Step 3/4 : RUN pip install python-dotenv
---> Running in 5fffd3fe4042
Collecting python-dotenv
Downloading python_dotenv-0.15.0-py2.py3-none-any.whl (18 kB)
Installing collected packages: python-dotenv
Successfully installed python-dotenv-0.15.0
Removing intermediate container 5fffd3fe4042
---> 2cd0942f520c
...
但是,当我运行 docker-compose exec container_name pip list时,列表 python-dotenv库没有。
我在0.14或0.15版本中尝试使用 python:3.9python:3.8进行测试。
当然,当我运行 python-dotenv时,一切都很好。
为什么Dockerfile中的 docker-compose exec container_name pip install python-dotenv命令未正确安装?

最佳答案

我不使用docker-compose,但是由于您的标题表明Dockerfile不能正常工作,因此我可以告诉您,这显然不是问题。您的Dockerfile似乎正常工作:

>>> cat Dockerfile
FROM python:3.9
WORKDIR /usr/src/app
RUN pip install python-dotenv

>>> docker build -t so2 .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM python:3.9
3.9: Pulling from library/python
e4c3d3e4f7b0: Pull complete
101c41d0463b: Pull complete
8275efcd805f: Pull complete
751620502a7a: Pull complete
0a5e725150a2: Pull complete
397dba5694db: Pull complete
b1d09d0eabcb: Pull complete
475299e7c7f3: Pull complete
d2fe14d8e6bc: Pull complete
Digest: sha256:429b2fd1f6657e4176d81815dc9e66477d74f8cbf986883c024c9b97f7d4d5a6
Status: Downloaded newer image for python:3.9
---> 5336a27a9b1f
Step 2/3 : WORKDIR /usr/src/app
---> Running in 37b03142a9b6
Removing intermediate container 37b03142a9b6
---> 4677ab34ce84
Step 3/3 : RUN pip install python-dotenv
---> Running in e89d17be1a32
Collecting python-dotenv
Downloading python_dotenv-0.15.0-py2.py3-none-any.whl (18 kB)
Installing collected packages: python-dotenv
Successfully installed python-dotenv-0.15.0
Removing intermediate container e89d17be1a32
---> 55d00eeae4b4
Successfully built 55d00eeae4b4
Successfully tagged so2:latest

>>> docker run -it so2 bash
root@d211989c4bd7:/usr/src/app# pip list
Package Version
------------- -------
pip 20.2.4
python-dotenv 0.15.0
setuptools 50.3.2
wheel 0.35.1
root@d211989c4bd7:/usr/src/app# exit

>>> docker run -it so2
Python 3.9.0 (default, Oct 13 2020, 20:14:06)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dotenv import load_dotenv; load_dotenv()
True
>>>
>>>代表我在MacBook Pro终端窗口中的提示。

关于python - Dockerfile没有安装python-dotenv库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64628209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com