docker build 构建镜像到docker容器

1.前提条件:有docker容器运行,并且开启了远程访问

2.配置pom.xml



   com.spotify
   docker-maven-plugin
   1.0.0
   
      
      docker-repostory
      http://192.168.52.206:2375
      ${project.artifactId}
      ${project.build.outputDirectory}
      
         
            ${project.build.directory}
            ${project.build.finalName}.jar
         
      
   

3.配置Dockerfile

FROM java:8
MAINTAINER "Liu Guang Hu"
ADD register-center.jar register-center.jar
EXPOSE 8082
CMD java -jar register-center.jar


4.运行步骤

docker build 构建镜像到docker容器_第1张图片

5.结果

"C:\Program Files\Java\jdk1.8.0_131\bin\java.exe" -Dmaven.multiModuleProjectDirectory=E:\Mywork\cloud-service\register-center -Dmaven.home=E:\maven\apache-maven-3.3.9 -Dclassworlds.conf=E:\maven\apache-maven-3.3.9\bin\m2.conf -javaagent:D:\SoftwareInstall\ideaIU-2018.3.3.win\lib\idea_rt.jar=61607:D:\SoftwareInstall\ideaIU-2018.3.3.win\bin -Dfile.encoding=UTF-8 -classpath E:\maven\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3.3 -s E:\maven\apache-maven-3.3.9\conf\mywork.xml com.spotify:docker-maven-plugin:1.0.0:build
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building register-center 2.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ register-center ---
[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier, NoOpRegistryAuthSupplier]
[INFO] Copying E:\Mywork\cloud-service\register-center\target\register-center.jar -> E:\Mywork\cloud-service\register-center\target\docker\register-center.jar
[INFO] Copying E:\Mywork\cloud-service\register-center\target\classes\bootstrap.yml -> E:\Mywork\cloud-service\register-center\target\docker\bootstrap.yml
[INFO] Copying E:\Mywork\cloud-service\register-center\target\classes\com\cloud\register\RegisterCenterApplication.class -> E:\Mywork\cloud-service\register-center\target\docker\com\cloud\register\RegisterCenterApplication.class
[INFO] Copying E:\Mywork\cloud-service\register-center\target\classes\Dockerfile -> E:\Mywork\cloud-service\register-center\target\docker\Dockerfile
[INFO] Building image register-center
Step 1/5 : FROM java:8

 ---> d23bdf5b1b1b
Step 2/5 : MAINTAINER "Liu Guang Hu"

 ---> Using cache
 ---> 422beeee27f5
Step 3/5 : ADD register-center.jar register-center.jar

 ---> Using cache
 ---> b7ee401b27d8
Step 4/5 : EXPOSE 8082

 ---> Using cache
 ---> 319e725e5bd3
Step 5/5 : CMD java -jar register-center.jar

 ---> Using cache
 ---> 0b6423684124
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 0b6423684124
Successfully tagged register-center:latest
[INFO] Built register-center
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.857 s
[INFO] Finished at: 2019-04-26T13:02:51+08:00
[INFO] Final Memory: 27M/185M
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0


6.查看镜像

docker build 构建镜像到docker容器_第2张图片

7.启动Spring Boot的Docker 容器

通过以下命令运行所构建的镜像,在后台运行容器,并将容器的8761端口绑定到宿主机的8761端口上

docker run -d -p 8761:8761 127.0.0.1:5000/register-center

输入http://localhost:8761

你可能感兴趣的:(docker)