I need to run a python command while building a docker image. My docker file is as follows
FROM python:3.8.13-slim-buster
RUN /usr/local/bin/python3 -c "import yaml"
When I run docker build . -t hello
, I get the following error:
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM python:3.8.13-slim-buster
---> 289f4e681a96
Step 2/2 : RUN /usr/local/bin/python3 -c "import yaml"
---> Running in 4eb13a1a1e9a
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'yaml'
2
Answers
The
yaml
module is not a part of Python’s standard library. You’ll need to install it withYou need to install the pyyaml package also. You can modify your Dockerfile as below: