Reputation: 1033
When I am inside the container, the following works:
pip uninstall -y -r <(pip freeze)
Yet when I try to do the same in my Dockerfile like this:
RUN pip uninstall -y -r <(pip freeze)
I get:
------
> [ 7/10] RUN pip uninstall -y -r <(pip freeze):
#11 0.182 /bin/sh: 1: Syntax error: "(" unexpected
------
executor failed running [/bin/sh -c pip uninstall -y -r <(pip freeze)]: exit code: 2
How do I re-write this command to make it happy?
I am using this work around. Still interested in the one-liner answer however
RUN pip freeze > to_delete.txt
RUN pip uninstall -y -r to_delete.txt
Upvotes: 3
Views: 1683
Reputation: 31564
The default shell
for RUN
is sh
which looks not compatiable with above command.
You could change the shell for RUN
to bash
to make it work.
Dockerfile:
FROM python:3
SHELL ["/bin/bash", "-c"]
RUN pip install pyyaml
RUN pip uninstall -y -r <(pip freeze)
Execution:
$ docker build -t abc:1 .
Sending build context to Docker daemon 5.12kB
Step 1/4 : FROM python:3
---> da24d18bf4bf
Step 2/4 : SHELL ["/bin/bash", "-c"]
---> Running in da64b8004392
Removing intermediate container da64b8004392
---> 4204713810f9
Step 3/4 : RUN pip install pyyaml
---> Running in 17a91e8cc768
Collecting pyyaml
Downloading PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl (630 kB)
Installing collected packages: pyyaml
Successfully installed pyyaml-5.4.1
WARNING: You are using pip version 20.3.3; however, version 21.2.4 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Removing intermediate container 17a91e8cc768
---> 1e6dba7439ac
Step 4/4 : RUN pip uninstall -y -r <(pip freeze)
---> Running in 256f7194350c
Found existing installation: PyYAML 5.4.1
Uninstalling PyYAML-5.4.1:
Successfully uninstalled PyYAML-5.4.1
Removing intermediate container 256f7194350c
---> 10346fb83333
Successfully built 10346fb83333
Successfully tagged abc:1
Upvotes: 5