目录
一:pip安装(此方式安装未成功)
- 安装安装python-pip
yum -y install epel-release
yum -y install python-pip
- pip升级
python -m pip install --upgrade pip -ihttp://pypi.douban.com/simple --trusted-host pypi.douban.com
- 安装docker-compose
pip install docker-compose
- 检查安装是否完成
docker-compose version
二:curl安装(使用此方式安装成功)
- 安装
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
- 授权
chmod +x /usr/local/bin/docker-compose
- 检查安装是否完成
docker-compose version
三:docker-compose部署
- 构建含有entrypoint.sh脚本的jdk镜像
entrypoint.sh文件内容
#!/bin/sh
#set -x
#******************************************************************************
# @file : entrypoint.sh
# @author : simon
# @date : 2018-08-28 15:18:43
#
# @brief : entry point for manage service start order
# history : init
#******************************************************************************
: ${SLEEP_SECOND:=2}
wait_for() {
echo Waiting for $1 to listen on $2...
while ! nc -z $1 $2; do echo waiting...; sleep $SLEEP_SECOND; done
}
declare DEPENDS
declare CMD
while getopts "d:c:" arg
do
case $arg in
d)
DEPENDS=$OPTARG
;;
c)
CMD=$OPTARG
;;
?)
echo "unkonw argument"
exit 1
;;
esac
done
for var in ${DEPENDS//,/}
do
host=${var%:*}
port=${var#*:}
wait_for $host $port
done
eval $CMD
#避免执行完命令之后退出容器
tail -f /dev/null
Dockerfile文件内容
FROM openjdk:8u181-jdk-alpine
ADD entrypoint.sh /entrypoint.sh
RUN sh -c 'chmod 777 /entrypoint.sh'
README.md文件构建镜像命令
docker build -t semanteme/openjdk8u181:0.0.1 .
- docker-compose构建文件
version: '3'
services:
eureka:
restart: always
image: "semanteme/eureka:latest" # 镜像名:标签名
hostname: eureka # 注册中心的hostname一定要有,且必须和代码中配置文件里的hostname一致
networks:
- finance-net # 加入的网络
environment:
- TZ=Asia/Shanghai
- SLEEP_SECOND=4
depends_on:
- config
ports:
- "9091:9091" # 映射的端口号,和代码中配置文件里的端口号一致
tty: true
entrypoint: /entrypoint.sh -d config:9093 -c 'java -Djava.security.egd=file:/dev/./urandom -Dlogs.home=./logs -Dlogging.config=./config/logback-spring.xml -Dspring.config.location=file:./config/ -Dspring.pid.file=./logs/application.pid -Dspring.pid.fail-on-write-error=true -jar /eureka/lib/eureka.jar';
config:
restart: always
image: "semanteme/config:latest"
hostname: config
networks:
- finance-net
environment:
- TZ=Asia/Shanghai
ports:
- "9093:9093"
gateway:
restart: always
image: "semanteme/gateway:latest"
hostname: gateway
networks:
- finance-net
environment:
- TZ=Asia/Shanghai
- SLEEP_SECOND=4
depends_on:
- eureka
ports:
- "9092:9092"
links:
- eureka
tty: true
entrypoint: /entrypoint.sh -d eureka:9091 -c 'java -Djava.security.egd=file:/dev/./urandom -Dlogs.home=./logs -Dlogging.config=./config/logback-spring.xml -Dspring.config.location=file:./config/ -Dspring.pid.file=./logs/application.pid -Dspring.pid.fail-on-write-error=true -jar /gateway/lib/gateway.jar';
cloud-agent-openstack:
restart: always
image: "semanteme/cloud-agent-openstack:latest"
hostname: cloud-agent-openstack
networks:
- finance-net
environment:
- TZ=Asia/Shanghai
- SLEEP_SECOND=4
depends_on:
- eureka
ports:
- "9095:9095"
links:
- eureka
tty: true
entrypoint: /entrypoint.sh -d gateway:9092 -c 'java -Djava.security.egd=file:/dev/./urandom -Dlogs.home=./logs -Dlogging.config=./config/logback-spring.xml -Dspring.config.location=file:./config/ -Dspring.pid.file=./logs/application.pid -Dspring.pid.fail-on-write-error=true -jar /cloud-agent-openstack/lib/cloud-agent-openstack.jar';
networks:
finance-net:
driver: bridge
四:常见问题及排查
- 启动失败
standard_init_linux.go:211: exec user process caused "no such file or directory"
原因1:entrypoint.sh文件格式编码错误
set ff #查看编码
set ff=unix #设置编码
原因2:entrypoint.sh文件启动脚本错误
#!/bin/bash #原脚本启动方式
#!/bin/sh #修改后脚本启动方式