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

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

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

在构builddockerfile的时候可以这样做吗? 如果是,那么有人可以帮我一把。

我可以通过使用sudo docker run -i -t image_name /bin/bash并修改文件来实现,但是这会创build一个容器。 现在,有没有办法将容器推回到图像上。

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

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

  2. 如果选项1似乎没有帮助尝试提交容器。 docker run容器做docker exec和评论文件中的行。 现在提交容器docker commit <conatainer-id> <some custom image name> https://docs.docker.com/engine/reference/commandline/commit/现在使用这个自定义图像&#x3002;