1.创建目录 并将jar复制到该目录

mkdir -p /app/config/

2.创建外部配置文件

vim application.yml
server:
  # 9081
  port: 9081

spring:
  application:
    # 服务名
    name: config-server
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          searchLocations: /usr/local/wlf_app/config-server/config/ 

注意:

  • linux 使用本地配置文件 /usr/local/wlf_app/config-server/config/
  • windows 使用本地配置文件 ///D:/config/

3.创建Dockerfile

vi Dockerfile
FROM java:8
MAINTAINER lwc
RUN mkdir -p /usr/local/config-server/logs
RUN mkdir -p /usr/local/config-server/files
RUN mkdir -p /usr/local/config-server/config
COPY config-server.jar /usr/local/config-server
COPY application.yml /usr/local/config-server
EXPOSE 9081
RUN bash -c 'touch /usr/local/config-server.jar'
ENTRYPOINT ["java","-jar","-Dspring.config.location=/usr/local/config-server/application.yml","-Duser.timezone=GMT+8","/usr/local/config-server/config-server.jar"]

# -Dspring.config.location=/usr/local/config-server/application.yml 使用外部配置文件

4.创建镜像

docker build -t config-server:1.0.0 .

5.运行

docker run -dit --restart=always \ 
--name config-server \
-v /app/wlf_app/config-server/config:/usr/local/wlf_app/config-server/config \ # 挂载配置文件
-p 9081:9081 config-server:1.0.0
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐