编译docker镜像
1.加速docker镜像下载速度
取决于网络速度,如果不慢的话,可以先不装
https://www.daocloud.io/mirror#accelerator-doc 执行下面的命令配置加速器 curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://4f7a7e6e.m.daocloud.io
2.下载springboot基础web工程
打开https://start.spring.io/,下载一个最基础带web的工程
加入helloworld
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @SpringBootApplication public class HelloApplication { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(HelloApplication.class,args); } }
配置application.yml
server: port: 8001
maven编译打包,重命名为hello.jar
3. 编写Dockerfile
FROM docker.io/fabric8/java-alpine-openjdk8-jdk ENV AB_OFF true EXPOSE 8001 COPY hello.jar /opt/ CMD java -jar /opt/hello.jar
4. 编译Dockerfile
docker build -t "camus/java" .
运行编译好的镜像
docker run -d -p8001:8001 camus/java