在创建新的Docker容器上运行命令 [英] Run commands on create a new Docker container
问题描述
是否可以在 Dockerfile
中添加类似 RUN
的指令,而不是在 docker build
命令,在使用 docker run
创建新容器时执行?我认为这对于初始化附加到主机文件系统的卷很有用。
Is it possible to add instructions like RUN
in Dockerfile
that, instead of run on docker build
command, execute when a new container is created with docker run
? I think this can be useful to initialize a volume attached to host file system.
推荐答案
看看 ENTRYPOINT 命令。这指定了在容器启动时要运行的命令,而不管有人在 docker run
命令行上作为命令提供了什么。实际上, ENTRYPOINT
脚本的工作就是解释传递给 docker run
的任何命令。
Take a look at the ENTRYPOINT command. This specifies a command to run when the container starts, regardless of what someone provides as a command on the docker run
command line. In fact, it is the job of the ENTRYPOINT
script to interpret any command passed to docker run
.
这篇关于在创建新的Docker容器上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!