修改在 Docker 镜像中使用 pip 安装的 python 文件

lij*_*050 1 pip amazon-web-services python-2.7 docker

我在 docker 中安装了一个名为 requests-aws4auth 的 python 模块,使用RUN pip install requests-aws4auth

现在我想通过进入cd /opt/conda/lib/python2.7/site-packages/requests_aws4auth/并注释aws4auth.py文件中的一行来修改它。我在构建 docker 时已经安装了 vim。

是否可以在构建 dockerfile 时执行此操作?如果是的话,有人可以帮助我吗?

我可以通过使用sudo docker run -i -t image_name /bin/bash和修改文件来做到这一点,但这将创建一个容器。现在,有什么办法可以将容器推回镜像吗?

mch*_*wre 5

有两种方法可以做到这一点:

  1. 添加一些 sed 命令,在 dockerfile 中的命令之后注释文件中的行,pip install如下所示 - RUN pip install requests-aws4auth RUN sed -e '/BBB/ s/^#*/#/' -i file #some logic to comment the line 构建 docker 映像并使用它。

  2. 如果选项 1 似乎没有帮助,请尝试提交容器。 docker run容器执行docker exec并注释文件中的行。现在提交容器docker commit <conatainer-id> <some custom image name> https://docs.docker.com/engine/reference/commandline/commit/ 现在使用此自定义映像。