SpringCloud 05
创建docker镜像
可以不用每次都在本机启动服务
docker run -p 端口 -d 后台运行 --link 指定网络host文件映射 -e 定义变量 -v文件挂载
修改一下server端的yml ,将值改为以下样式:
register-with-eureka: ${REGISTER_WITH_EUREKA:TRUE}
service-url:
defaultZone: ${EUREKA_SERVER_URL:http://locasthost:8761/eureka}
这样可以通过docker的-e来进行赋值,完整yml:
server:
port: 8761
spring:
application:
name: eureka-server
eureka:
server:
eviction-interval-timer-in-ms: 10000
renewal-percent-threshold: 0.85
instance:
instance-id: ${eureka.instance.hostname}:${spring.application.name}:${server.port}
hostname: localhost
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
client:
register-with-eureka: ${REGISTER_WITH_EUREKA:TRUE}
service-url:
defaultZone: ${EUREKA_SERVER_URL:http://locasthost:8761/eureka}
fetch-registry: true
下面进行打包,点击右边的Maven:
双击install
可以看到这里正在进行打包:
打开target文件夹,若没有显示则按以下操作:
创建一个docker文件夹,将jar文件粘过来,并改名字
写一个Dockerfile文件
FROM openjdk:8
ENV workdir=/root/app/eureka-server
COPY . ${workdir} WORKDIR ${workdir}
EXPOSE 8761
CMD ["java","-jar","eureka-server-1.0.jar"]
写一个脚本
cd .. && docker build ./eureka-server -t eureka-server:1.0
之后内容后期在学