一、新建项目、本地启动访问正常--省略
二、main目录下新建docker文件夹、该文件夹下新建Dockerfile、编写Dockerfile
FROM java:8VOLUME /tmpADD Eureka.jar app.jarRUN bash -c 'touch /app.jar'ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]EXPOSE 8761
三、pom.xml中引入docker-maven插件
com.spotify docker-maven-plugin 0.4.13 itmuch/docker-eureka:0.0.1 虚拟机访问的ip:port 本地虚拟机安装的default目录 ${project.basedir}/src/main/docker / ${project.build.directory} ${project.build.finalName}.jar
四、切换项目目录下执行mvn package -Dmaven.test.skip=true docker:build
五、构建完成后在虚拟机上通过docker images查看该镜像是否构建成功
docker:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE itmuch/docker-eureka 0.0.1 967be7faa1ea 27 seconds ago 697MB java 8 d23bdf5b1b1b 14 months ago 643MB六、启动镜像docker run -d -p 8761:8761 itmuch/docker-eureka:0.0.1
七、通过指令查看镜像是否启动正常
docker:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1dde97c6d33 itmuch/docker-eureka:0.0.1 "java -Djava.securit…" 57 seconds ago Up 55 seconds 0.0.0.0:8761->8761/tcp cocky_sammet