新建docker目录,把项目打包成jar文件,并上传到该目录,创建Dockerfile文件,文件内容如下:
1 # 基于哪个镜像 2 FROM java:8 3 4 # 将本地文件夹挂载到当前容器 5 VOLUME /home/container 6 7 # 这个地方jar包名称改成自己的jar名称 8 ADD eureka-server1.jar app.jar 9 RUN bash -c 'touch /app.jar' 10 11 # 开放8761端口 12 EXPOSE 8761 13 14 # 配置容器启动后执行的命令 15 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
运行:docker build -t eureka-server1 . 打包镜像。
然后运行:docker images 查看该容器的所有镜像。
通过ip访问服务