博客已迁移至https://drivingc.com,本站停止更新.

dockerfile中的entrypoint.sh

set —

entrypoint.sh中经常出现
set -- mongod "$@"
经测试是改变参数用的,例如脚本test.sh

echo "$@"
set -- 3 "$@"
echo "$@"

执行./test.sh 1 2
会输出
1 2
3 1 2
可见当执行set — 之后$@的值被改变了

常用dockerfile中的entrypoint.sh

1.先看php7.0-fpm的

#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
    set -- php-fpm "$@"
fi

exec "$@"

这里只是判断了一下如果CMD里的命令以-开头的话会自动加上php-fpm
2.看mongo3.4的

#!/bin/bash
set -e

if [ "${1:0:1}" = '-' ]; then
    set -- mongod "$@"
fi

# allow the container to be started with `--user`
# all mongo* commands should be dropped to the correct user
if [[ "$1" == mongo* ]] && [ "$(id -u)" = '0' ]; then
    if [ "$1" = 'mongod' ]; then
        chown -R mongodb /data/configdb /data/db
    fi
    exec gosu mongodb "$BASH_SOURCE" "$@"
fi

# you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients.
# https://docs.mongodb.com/manual/administration/production-notes/#configuring-numa-on-linux
if [[ "$1" == mongo* ]]; then
    numa='numactl --interleave=all'
    if $numa true &> /dev/null; then
        set -- $numa "$@"
    fi
fi

exec "$@"

同样的,如果CMD命令以-开头,自动加上mongod命令
下面如果是root执行mongod命令的话会更改文件夹权限,然后换到mongodb用户再执行本脚本
用numactl 设置了以numa方式调度cpu,numa是一种多cpu的内存调度方式

本文链接:https://kupposhadow.com/p/5934c1f2c836110b3531eda6
本站采用「署名 4.0 国际(CC BY 4.0)」创作共享协议。只要在使用时署名,那么使用者可以对本站所有原创内容进行转载、二次创作、商业性使用。
这篇文章还没有评论