spring cloud
bootstrap.yml
设置nacos
环境变量需求是有多台服务器,每次打包都要修改
bootstrap.yml
的ip地址和命名空间等 比较麻烦,所以就设置一个环境变量一劳永逸技术交流博客 http://idea.coderyj.com/
1. spring cloud
bootstrap.yml
设置变量
yml
custom-nacos:
ip: ${NACOS_SERVER_IP:172.16.1.113}
port: ${NACOS_SERVER_PORT:8848}
namespace: ${NACOS_APP_NAMESPACE:nacos-robot-web}
username: ${NACOS_AUTH_USERNAME:nacos}
password: ${NACOS_AUTH_PASSWORD:nacos}
spring:
application:
name: nacos-web
cloud:
nacos:
discovery:
server-addr: ${custom-nacos.ip}:${custom-nacos.port}
namespace: ${custom-nacos.namespace}
username: ${custom-nacos.username}
password: ${custom-nacos.password}
#配置中心设置
config:
#设置配置中心服务端地址
server-addr: ${custom-nacos.ip}:${custom-nacos.port}
namespace: ${custom-nacos.namespace}
file-extension: yaml
group: DEFAULT_GROUP
refresh-enabled: true
extension-configs[0]:
data-id: common.yaml
group: DEFAULT_GROUP
refresh-enabled: true
username: ${custom-nacos.username}
password: ${custom-nacos.password}
# 上传文件大小设置
servlet:
multipart:
max-file-size: 10MB
max-request-size: 100MB
- ip: ${NACOS_SERVER_IP:172.16.1.113}
- port: ${NACOS_SERVER_PORT:8848}
- namespace: ${NACOS_APP_NAMESPACE:nacos-robot-web}
- username: ${NACOS_AUTH_USERNAME:nacos}
- password: ${NACOS_AUTH_PASSWORD:nacos}
1.docker-compose 文件设置
java
version: '2'
services:
web:
image: "nacos-web"
networks:
- overlay_net
ports:
- "8182:8182"
restart: always
environment:
- TZ=Asia/Shanghai
- JAVA_OPTS=-XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC
container_name: nacos-web
env_file:
- ./custom-application-config.env
volumes:
- /data/ftp/root:/home
networks:
overlay_net:
env_file:
- ./custom-application-config.env
- env 文件
java
NACOS_SERVER_IP=172.16.1.113
NACOS_SERVER_PORT=8848
NACOS_APP_NAMESPACE=nacos-robot-web
NACOS_AUTH_USERNAME=nacos
NACOS_AUTH_PASSWORD=nacos
2.在Dockerfile
设置环境变量
FROM openjdk:8
# 将当前目录下的*.jar添加到镜像中去,并且命名为app.jar
ADD target/track-web-exe.jar app.jar
# 开放tcp端口
EXPOSE 8182/tcp
ENV LANG C.UTF-8
ENV NACOS_SERVER_IP=172.16.1.113
ENV NACOS_SERVER_PORT=8848
NACOS_APP_NAMESPACE=nacos-robot-web
NACOS_AUTH_USERNAME=nacos
NACOS_AUTH_PASSWORD=nacos
# copy 修改启动配置文件
#COPY src/main/resources/bootstrap.yml ./config/bootstrap.yml
# 把字体拷贝到docker容器里面
COPY src/main/resources/fonts/simsun.ttc /usr/share/fonts/
# 镜像启动的时候执行这个命令
CMD exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar
3.重置配置文件
FROM openjdk:8
# 将当前目录下的*.jar添加到镜像中去,并且命名为app.jar
ADD target/track-web-exe.jar app.jar
# 开放tcp端口
EXPOSE 8182/tcp
ENV LANG C.UTF-8
# copy 修改启动配置文件
COPY src/main/resources/bootstrap.yml ./config/bootstrap.yml
# 把字体拷贝到docker容器里面
COPY src/main/resources/fonts/simsun.ttc /usr/share/fonts/
# 镜像启动的时候执行这个命令
CMD exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar
- COPY src/main/resources/bootstrap.yml ./config/bootstrap.yml
- 将
bootstrap.yml
拷贝到服务器上进行镜像打包即可- 镜像打包命令
docker-build -t track-web .