构建最新版本镜像
flink最新1.12版本镜像由于官方目前没有更新,这里自己构建.
我这里fork了官方的源码构建了一份,构建源码地址可以参考我的Github:
https://github.com/darebeat/docker-center/tree/master/build/flink
# 如果不想自己构建,可以用我已经构建好的版本.
docker pull darebeat/flink:1.12.0-scala_2.11
docker查看并创建本地公共网络
# 根据需要选择命令执行,如果 deploy 网络已创建,可忽略
docker network ls
docker network inspect deploy
docker netwok rm deploy
docker network create --driver=bridge --subnet=172.10.0.0/16 deploy
通过docker-compose部署管理应用
# 环境变量
cat << EOF> .env
FLINK_IMAGE_NAME=darebeat/flink
FLINK_VERSION=1.12.0-scala_2.11
EOF
# docker-compose配置文件 docker-compose.yaml
cat << EOF> docker-compose-flink.yaml
version: '3'
services:
jobmanager:
image: ${FLINK_IMAGE_NAME:-darebeat/flink}:${FLINK_VERSION:-1.12.0-scala_2.11}
container_name: flink-jobmanager
hostname: jobmanager
networks:
deploy:
ipv4_address: 172.10.0.2
aliases:
- jobmanager
expose:
- "6123"
ports:
- "8081:8081"
# command: jobmanager # 如果用这种方式启动,查看输出结果需要在运行的容器日志中查看
command:
- bash
- -c
- |
sed -i 's/start-foreground/start/g' /docker-entrypoint.sh
/docker-entrypoint.sh jobmanager
tail -f /docker-entrypoint.sh
environment:
- |
FLINK_PROPERTIES=
jobmanager.rpc.address: jobmanager
volumes:
- ./config/flink-jars/:/opt/flink/connector-lib/
taskmanager:
image: ${FLINK_IMAGE_NAME:-darebeat/flink}:${FLINK_VERSION:-1.12.0-scala_2.11}
container_name: flink-taskmanager
hostname: taskmanager
networks:
deploy:
ipv4_address: 172.10.0.3
aliases:
- taskmanager
expose:
- "6121"
- "6122"
depends_on:
- jobmanager
# command: taskmanager # 如果用这种方式启动,查看输出结果需要在运行的容器日志中查看
command:
- bash
- -c
- |
sed -i 's/start-foreground/start/g' /docker-entrypoint.sh
/docker-entrypoint.sh taskmanager
tail -f /docker-entrypoint.sh
scale: 1
environment:
- |
FLINK_PROPERTIES=
jobmanager.rpc.address: jobmanager
taskmanager.numberOfTaskSlots: 8 # 根据自己的机器可以配置更低或更高的数字,配置越高,配置的数字可以越高
networks:
deploy:
external: true
EOF
# docker-compose管理
docker-compose -f docker-compose-flink.yaml up -d # 启动
docker-compose -f docker-compose-flink.yaml down -v # 停止并移除实例
浏览器打开 http://127.0.0.1:8081 可以看到dashboard
更多docker应用,请参考我的Github:
https://github.com/darebeat/docker-center/tree/master/deploy