erlang 啟動(dòng)
docker容器是否退出跟容器的主進(jìn)程有關(guān)臊旭,主進(jìn)程結(jié)束后乞而,容器就exit了量没,那么erlang in docker時(shí),erl shell做為主進(jìn)程持际,erl shell 需以前臺(tái)方式啟動(dòng)沃琅,此時(shí)docker run必須指定-t
以監(jiān)聽(tīng)shell輸入,否則docker run -d erlang erl
會(huì)立刻exit蜘欲,應(yīng)該用docker run -dt erlang erl
才能保持容器在后臺(tái)運(yùn)行益眉。
當(dāng)用docker swarm 創(chuàng)建服務(wù)時(shí),不能指定-t
姥份,那么erlang集群容器就會(huì)exit郭脂,此時(shí)需要將erl啟動(dòng)命令改為noshell 啟動(dòng),即erl -noshell -name xxx
即可澈歉。
docker swarm中erlang集群互聯(lián)
TODO
以下是各種腳本:
build.sh
#!/bin/bash
git checkout .
chmod +x rebar
chmod +x ./docker/start.sh
make deps
make clean
cp ./docker/Dockerfile ./../Dockerfile
docker rmi songcf/scene:v1 --force
docker build -t="songcf/scene:v1" ./../
rm -f ./../Dockerfile
Dockerfile
FROM erlang:latest
MAINTAINER Docker SongCF <fuxiao333@qq.com>
ENV SOURCE_DIR /jh/source/scene/
WORKDIR $SOURCE_DIR
COPY ./scene $SOURCE_DIR
EXPOSE 9901
EXPOSE 9911
RUN ["chmod", "+x", "rebar"]
RUN ["make"]
RUN ["make", "g"]
RUN ["make"]
ENTRYPOINT ["/bin/bash", "./docker/start.sh"]
CMD ["./docker/start.sh"]
start.sh
#!/bin/bash
# 1.更改leader_selection:app_id
sed -i "s/platform_scene_app_id/$LEADER_SELECT_APP_ID/g" scripts/scene.config
# 2.更改mysql配置
sed -i "s/localhost/$MYSQL_IP/g" scripts/scene.configsed -i "s/port, 3306/port, $MYSQL_PORT/g" scripts/scene.config
# 3.更改erlang node ip
# 按照自己的網(wǎng)絡(luò)更改 |grep 10.0|grep /24
# ip a|grep inet|grep 10.0|grep /24|awk '{print $2}'|awk -F"/" '{print $1}'
NODE_IP=$(ip a|grep inet|grep ${SUBNET}|grep ${SUBNET_MASK}|awk '{print $2}'|awk -F"/" '{print $1}')
erl -noshell -pa ebin -pa deps/*/ebin -name scene@${NODE_IP} -config scripts/scene.config -s scene
boot
# sigle start
docker run -d \
--name platform_scene \
-w /jh/source/scene/ \
-e LEADER_SELECT_APP_ID=dockerswarm_platform_scene \
-e MYSQL_IP=127.0.0.1 \
-e MYSQL_PORT=3306 \
-e SUBNET=127.0 \
-e SUBNET_MASK=/8 \
songcf/scene:v1
# docker swarm service
docker network create -d overlay --subnet 10.0.9.0/24 --opt encrypted net-scene
curl -X DELETE http://127.0.0.1:10001/api/v1/leaderselect/dockerswarm_platform_scene
docker service create \
--name platform_scene \
--replicas 2 \
--network net-scene \
-e LEADER_SELECT_APP_ID=dockerswarm_platform_scene \
-e MYSQL_IP=192.168.31.96 \
-e MYSQL_PORT=3306 \
-e SUBNET=10.0 \
-e SUBNET_MASK=/24 \
songcf/scene:v1