1、进入环境变量已被替换的容器,某个配置文件,符合预期。如图1
2、进入环境变量未被替换的容器,某个配置文件,不符合预期。如图2
3、查看环境变量已被替换的容器的日志。有相应环境变量已被替换的提示。如图3
2020/8/11 下午3:03:11 PCS_CFG_NGINX_SERVER_NAME=pcs.wjtest.chinamcloud.cn 2020/8/11 下午3:03:11 PCS_CFG_API_HOST_INFO=http://pcsapi.wjtest.chinamcloud.cn 2020/8/11 下午3:03:11 PCS_CFG_API_BASE_URL=/v1 2020/8/11 下午3:03:11 PCS_CFG_CALLBACK_LOGIN=http://cmcgroup.wjtest.chinamcloud.cn/login/index?call_back=http://pcs.wjtest.chinamcloud.cn/#/topic/add 2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_URL=https://cmcconsole.wjtest.chinamcloud.cn 2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_CSS=/cmc/cmc_header_left.css 2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_JS=/cmc/cmc_header_left.js 2020/8/11 下午3:03:11 PCS_CFG_YS_FLAG=申请任务 2020/8/11 下午3:03:11 PCS_CFG_BQ_FLAG=0 2020/8/11 下午3:03:11 PCS_CFG_NGINX_SERVER_NAME replace pcs.wjtest.chinamcloud.cn -> /etc/nginx/conf.d/pcs.conf 2020/8/11 下午3:03:11 PCS_CFG_API_HOST_INFO replace http://pcsapi.wjtest.chinamcloud.cn -> /etc/nginx/conf.d/pcs.conf 2020/8/11 下午3:03:11 PCS_CFG_API_BASE_URL replace /v1 -> /etc/nginx/conf.d/pcs.conf 2020/8/11 下午3:03:11 sed: -e expression #1, char 120: unknown option to `s' 2020/8/11 下午3:03:11 PCS_CFG_CALLBACK_LOGIN replace http://cmcgroup.wjtest.chinamcloud.cn/login/index?call_back=http://pcs.wjtest.chinamcloud.cn/#/topic/add -> /mcloud/www/pcs/build/config.js 2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_URL replace https://cmcconsole.wjtest.chinamcloud.cn -> /mcloud/www/pcs/build/config.js 2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_CSS replace /cmc/cmc_header_left.css -> /mcloud/www/pcs/build/config.js 2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_JS replace /cmc/cmc_header_left.js -> /mcloud/www/pcs/build/config.js 2020/8/11 下午3:03:11 PCS_CFG_YS_FLAG replace 申请任务 -> /mcloud/www/pcs/build/config.js 2020/8/11 下午3:03:11 PCS_CFG_BQ_FLAG replace 0 -> /mcloud/www/pcs/build/config.js 2020/8/11 下午3:03:11 /config/init/cronlog.sh: line 4: LOG_NAME: unbound variable
4、查看环境变量未被替换的容器的日志。无相应环境变量已被替换的提示。且报错:Invalid Date Invalid Date grabbing logs: EOF。即无效的日期 获取日志:EOF。如图4
Invalid Date Invalid Date grabbing logs: EOF
5、查看环境变量未被替换的容器,升级(Upgrade) – 命令(Command) – 入口(Entry Point):/bin/bash。而查看环境变量已被替换的容器,其值为空。其作用为配置容器启动后执行的命令。如图5
6、编辑环境变量未被替换的容器,升级(Upgrade) – 命令(Command) – 入口(Entry Point):。设置其值为空。重新升级。容器的日志未再报错,环境变量已被替换。此时,容器启动后执行的命令脚本为:/config/bootstrap.sh。此脚本中包含环境变量替换的实现。
#!/bin/bash localedef -i en_US -f UTF-8 en_US.UTF-8 set -e set -u # Supervisord default params SUPERVISOR_PARAMS='-c /etc/supervisord.conf' # Create directories for supervisor's UNIX socket and logs (which might be missing # as container might start with /data mounted from another data-container). mkdir -p /data/conf /data/run /data/logs chmod 711 /data/conf /data/run /data/logs if [ "$(ls /config/init/)" ]; then for init in /config/init/*.sh; do . $init done fi # We have TTY, so probably an interactive container... if test -t 0; then # Run supervisord detached... supervisord $SUPERVISOR_PARAMS # Some command(s) has been passed to container? Execute them and exit. # No commands provided? Run bash. if [[ $@ ]]; then eval $@ else export PS1='[/u@/h : /w]/$ ' /bin/bash fi # Detached mode? Run supervisord in foreground, which will stay until container is stopped. else # If some extra params were passed, execute them before. # @TODO It is a bit confusing that the passed command runs *before* supervisord, # while in interactive mode they run *after* supervisor. # Not sure about that, but maybe when any command is passed to container, # it should be executed *always* after supervisord? And when the command ends, # container exits as well. if [[ $@ ]]; then eval $@ fi supervisord -n $SUPERVISOR_PARAMS fi
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250545.html