linux - Shell 命令不会在 Docker 构建中运行
问题描述
当我在容器内时,以下工作:
pip uninstall -y -r <(pip freeze)
然而,当我尝试在我的 Dockerfile 中做同样的事情时:
RUN pip uninstall -y -r <(pip freeze)
我得到:
------
> [ 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
如何重新编写此命令以使其满意?
编辑:
我正在使用这项工作。然而,仍然对单行答案感兴趣
RUN pip freeze > to_delete.txt
RUN pip uninstall -y -r to_delete.txt
解决方案
默认值shell
是RUN
看起来sh
与上述命令不兼容。
您可以更改外壳RUN
以bash
使其工作。
Dockerfile:
FROM python:3
SHELL ["/bin/bash", "-c"]
RUN pip install pyyaml
RUN pip uninstall -y -r <(pip freeze)
执行:
$ 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
推荐阅读
- log4j2 - Log4j2 不通过附加程序记录 Faces 异常
- drupal - drupal 7 taxonomy_vocabulary_machine_name_load 未显示字段
- android - Android - 未调用 TabLayout 侦听器回调
- php - 如何使 Pygame 游戏在线可执行?
- python - 无法安装图案
- spotify - 通过 Spotify API 获取流总数和跟踪发布日期
- node.js - AWS Lambda :: 如何在我的本地 ubuntu 机器上测试我的代码?
- android - 如何将进入动画设置为 RecyclerView 项目?
- charts - Amchart 响应问题
- hive - 为什么 Hive 和 bigSQL 中存在 1 条记录的数据不匹配?