修改从现有镜像创建的docker

修改从现有镜像创建的docker

本文介绍了修改从现有镜像创建的docker镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过一种方法,我基于现有图像创建了一个新图像.
我没有原始图像的Dockerfile,当容器启动时发生了一些事情我无法改变-就是那样.

By following a how-to, I've created a new image based on an existing one.
I don´t have the original images' Dockerfile and there are things happening when the container starts thatI can't change - that´s how it seems anyway.

是否可以修改基本映像的Dockerfile中的命令?

Is there a way to modify the commands in the Dockerfile of the base image?

例如,容器在启动时运行bash脚本,我想更改它.

For example the container runs a bash script when it starts, I want to change this.

推荐答案

要回答您的特定问题:"容器在启动时运行bash脚本,我想对此进行更改".假设您要运行/script.sh (图像的一部分)而不是默认值,则可以使用以下方法实例化容器:

To answer your specific q: "the container runs a bash script when it starts, i want to change this". Let's assume you want to run /script.sh (part of the image) instead of the default, you can instantiate a container using:

docker run --entrypoint /script.sh repo/image

如果 script.sh 不是图像的一部分,并且/或者您不希望每次使用上述-entrypoint 显式地指定它,则可以准备一个包含并运行您自己的 script.sh :

If script.sh isn't part of the image and/or you prefer not having to specify it explicitly each time with --entrypoint as above, you can prepare an image that contains and runs your own script.sh:

  1. 创建一个空目录并在其中复制或创建 script.sh
  2. 使用以下内容创建 Dockerfile :

FROM repo/image
ADD script.sh /
ENTRYPOINT /script.sh

  • docker build -t ="myimage".

    注意:

    • 运行容器时(第4步),不再需要指定-entrypoint ,因为我们已将其默认为 Dockerfile .
    • 就这么简单;无需注册docker hub或任何其他类似的东西(尽管当然建议及时;-)
    • When running the container (step 4), it's no longer necessary to specify --entrypoint since we have it defaulted in the Dockerfile.
    • It's really that simple; no need to sign up to docker hub or any such thing (although it's of course recommended in time ;-)

    这篇关于修改从现有镜像创建的docker镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 07-24 18:52