微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS学习笔记 - 8. docker 编译基于gofabric8的java应用镜像

编译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

5. 打开浏览器进行测试

http://127.0.0.1:8001/

原文地址:https://www.jb51.cc/centos/375525.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。