赞
踩
目录
1.2、修改application.properties配置文件
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.5.6</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.cjc</groupId>
- <artifactId>docker01</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>docker01</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
server.port=6001
HelloDocker类的内容为:
- @RestController
- public class HelloController {
- //获取配置文件的参数
- @Value("${server.port}")
- private String port;
- @RequestMapping("/hello/docker")
- public String helloDocker(){
- return "hello docker"+"\t"+port+"\t"+ UUID.randomUUID().toString();
- }
- @RequestMapping(value = "/hello/index",method = RequestMethod.GET)
- public String index(){
- return "服务端口:"+"\t"+port+"\t"+UUID.randomUUID().toString();
- }
- }
Dockerfile的文件内容:
- #基础镜像使用Java8
- FROM java:8
- #作者
- MAINTAINER cjc
- #VOLUME 指定临时文件目录为/tmp ,在主机/var/lib/docker目录下创建一个临时文件并链接到容器的/tmp
- VOLUME /tmp
- #将jar包添加到容器中并更名为cjc_docker.jar
- ADD docker01-0.0.1-SNAPSHOT.jar cjc_docker.jar
- #运行jar包
- RUN bash -c 'touch /cjc_docker.jar'
- ENTRYPOINT ["java","jar","/cjc_docker.jar"]
- #暴露6001端口作为微服务
- EXPOSE 6001
docker build -t cjc_docker:1.6 .
docker run -d -p 6001:6001 ba117b253063
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。