[英]Dockerfile: is it possible to reference overridden entrypoint and cmd?
I'm trying to build a image using mysql 5.6 from here as a base image. 我正在尝试使用mysql 5.6从此处构建映像作为基本映像。 I need to do some initialization before the database starts up, so I need to override the entrypoint: 我需要在数据库启动之前进行一些初始化,所以我需要覆盖入口点:
# Stuff in my Dockerfile
...
COPY my-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["my-entrypoint.sh"]
My entrypoint is fairly simple, too: 我的入口点也很简单:
#!/bin/bash
echo "Running my-entrypoint.sh"
# My initialization stuff here
...
# Call mysql entrypoint
/usr/local/bin/docker-entrypoint.sh mysqld
This seems to work, but I'd rather not have to hard-code the mysql entrypoint in my script (or my Dockerfile). 这似乎可行,但是我不想在脚本(或Dockerfile)中对mysql入口点进行硬编码。 Is there a way to reference the overridden entrypoint in my Dockerfile, so that it is available to my entrypoint script? 有没有办法在我的Dockerfile中引用覆盖的入口点,以便它对我的入口点脚本可用? Something like this, perhaps? 大概是这样吗?
COPY my-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["my-entrypoint.sh", BASE_ENTRYPOINT, BASE_CMD]
It has to appear in somewhere in someway, otherwise you can't get such information. 它必须以某种方式出现在某个地方,否则您将无法获得此类信息。
Option 1: use an ENV
for previous entrypoint in Dockerfile
, and then refer to it in your own entrypoint.sh: 选项1:对Dockerfile
先前入口点使用ENV
,然后在您自己的entrypoint.sh中引用它:
Dockerfile: Dockerfile:
FROM alpine:3.3 ENV MYSQL_ENTRYPOINT "/usr/bin/mysql mysqld" ADD entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"]
Entrypoint.sh: Entrypoint.sh:
#!/bin/sh echo $MYSQL_ENTRYPOINT
Option 2: just pass previous entrypoint command as parameter to your entrypoint: 选项2:只需将先前的entrypoint命令作为参数传递给您的入口点:
Dockerfile: Dockerfile:
FROM alpine:3.3 ADD entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"] CMD ["/usr/bin/mysql mysqld"]
Entrypoint.sh: Entrypoint.sh:
#!/bin/sh echo $1
Personally I prefer option #1. 我个人更喜欢选择#1。
2 ways: 2种方式:
Just pass it in after you specify your image, everything after that becomes the CMD
and appended to your ENTRYPOINT
. 您只需在指定图片后将其传递,之后的所有内容就会变成CMD
并附加到您的ENTRYPOINT
。 So... 所以...
# Stuff in my Dockerfile
...
COPY my-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["my-entrypoint.sh"]
Then docker run ... image <your-entrypoint-etc>
then just have your custom entrypoint pick up the 1st arg to it and use that however you need. 然后docker run ... image <your-entrypoint-etc>
然后让您的自定义入口点拾取第一个arg并根据需要使用它。
Second way, just pass it as an environment variable at runtime. 第二种方法,只需在运行时将其作为环境变量传递即可。
docker run ... -e MYSQL_ENTRYPOINT=<something> ...
And in your entrypoint script refer to the env variable ... $MYSQL_ENTRYPOINT ...
在入口点脚本中,请参考env变量... $MYSQL_ENTRYPOINT ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.