Reputation: 2968
My Dockerfile:
FROM python:3.9
WORKDIR /usr/src/app
RUN pip install python-dotenv
RUN pip install other_libraries...
During building container, message is displayed:
...
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
...
But when I run docker-compose exec container_name pip list
there is no on list python-dotenv
library.
I tried on python:3.9
, python:3.8
with python-dotenv
in 0.14 or 0.15 version.
Of course, when I run docker-compose exec container_name pip install python-dotenv
everything is okey.
Why RUN
command in Dockerfile not installed correctly?
Upvotes: 0
Views: 2907
Reputation: 9442
Step by step.
docker build -t dotenv_image:1.0 .
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dotenv_image 1.0 507f2d0505a0 4 minutes ago 891MB
↑Okay it is here
sh
shell to be able run commands and check what inside containerdocker run --rm -it --entrypoint sh dotenv_image:1.0
pip freeze
python-dotenv==0.15.0
Library is here
python -c 'from dotenv import load_dotenv; print("ALL OK" if load_dotenv() else "CAN NOT LOAD")';
ALL OK
↑Positive output
Upvotes: 2
Reputation: 23139
I don't use docker-compose, but since your title says that your Dockerfile isn't working right, I can tell you that that's apparently not the problem. Your Dockerfile seems to work just fine:
>>> 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
>>>
>>>
represent my prompt in my MacBook pro Terminal window.
Upvotes: 1