一、新建项目、本地启动访问正常--省略
二、main目录下新建docker文件夹、该文件夹下新建Dockerfile、编写Dockerfile
FROM java:8 VOLUME /tmp ADD Eureka.jar app.jar RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] EXPOSE 8761
三、pom.xml中引入docker-maven插件
<plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.13</version> <configuration> <imageName>itmuch/docker-eureka:0.0.1</imageName> <dockerHost>虚拟机访问的ip:port</dockerHost> <dockerCertPath>本地虚拟机安装的default目录</dockerCertPath> <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins>
四、切换项目目录下执行mvn package -Dmaven.test.skip=true docker:build
五、构建完成后在虚拟机上通过docker images查看该镜像是否构建成功
docker@default:~$ 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@default:~$ 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