取決於網絡速度,若是不慢的話,能夠先不裝java
https://www.daocloud.io/mirror#accelerator-doc 執行下面的命令配置加速器 curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://4f7a7e6e.m.daocloud.io
使用了加速器這個腳本之後,發現次日重啓電腦後,docker引擎沒法啓動。 unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid character '}' 咱們能夠看到多了一個,號 cat /etc/docker/daemon.json {"registry-mirrors": ["http://4f7a7e6e.m.daocloud.io"],} 打開文件,去掉那個多餘的,號便可 {"registry-mirrors": ["http://4f7a7e6e.m.daocloud.io"]} 從新啓動docker引擎 systemctl start docker
打開https://start.spring.io/,下載一個最基礎帶web的工程
加入helloworldweb
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.ymlspring
server: port: 8001
maven編譯打包,重命名爲hello.jardocker
FROM docker.io/fabric8/java-alpine-openjdk8-jdk ENV AB_OFF true EXPOSE 8001 COPY hello.jar /opt/ CMD java -jar /opt/hello.jar
FROM表示基礎鏡像是哪個,咱們這裏使用fabric8提供的java基礎鏡像 EVN AB_OFF 是這個鏡像中提供的環境變量,能夠在docker hub裏面查看含義 EXPOSE 8001 表示開放8001這個端口 COPY命令表示拷貝hello.jar這個文件到/opt/目錄下 CMD表示啓動之後執行這條命令,通常一個docker就放一個應用,而後能夠把這些應用經過link命令鏈接起來。 因此這裏通常就是執行啓動咱們應用的那條命令。
docker build -t "camus/java" .
docker run -d -p8001:8001 camus/java