我在postgres图像(https://github.com/docker-library/postgres/blob/master/10/Dockerfile)的Dockerfile中看到,最后容器的启动定义如下:
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]
如果我理解这一点,将postgres
参数转换为docker-entrypoint.sh
,以便脚本中的$1
替换为postgres
,脚本将被执行。
现在我的问题是,如果我可以基于postgres图像(FROM postgres
)定义我自己的Dockerfile,但是覆盖基础Dockerfile的CMD
并完成首先在启动时执行命令然后用docker-entrypoint.sh
参数执行postgres
?
像这样的东西:
FROM postgres
...
CMD <my-command> && [“postgres”]
你可以创建自己的qazxsw poi
my-entrypoint.sh
您的docker文件将如下所示
$ cat my-entrypoint.sh
#!/bin/bash
#do what you need here e.g. <my-command>
#next command will run postgres entrypoint will all params
docker-entrypoint.sh "$@"
是的,你可以做这样的事情
对于Dockerfile中的CMD命令,您有3种可能的语法
摘录自
FROM postgres
# your stuff
ENTRYPOINT ["my-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]
https://docs.docker.com/engine/reference/builder/#cmd
所以你可以使用任何,为了做你想要的,从(最后一个)的shell似乎很适合
您还可以启动一个可以完成所有工作的shell脚本