黑马程序员技术交流社区
标题:
【上海校区】在Docker中运行一个微服务
[打印本页]
作者:
不二晨
时间:
2018-7-13 09:46
标题:
【上海校区】在Docker中运行一个微服务
一 在windows中使用maven构建microservice-discovery-eureka可运行的jar包
C:\WINDOWS\system32>cd F:\springcloud\temp\microservice-discovery-eureka
C:\WINDOWS\system32>f:
F:\springcloud\temp\microservice-discovery-eureka>mvn clean package
在F:\springcloud\temp\microservice-discovery-eureka\target目录生成文件microservice-discovery-eureka-0.0.1-SNAPSHOT.jar
二 将microservice-discovery-eureka-0.0.1-SNAPSHOT.jar拷贝到Linux环境
[root@master eureka]# ll
total 40952
-rw-r--r-- 1 root root 41929619 Jul 7 14:29 microservice-discovery-eureka-0.0.1-SNAPSHOT.jar
三 在microservice-discovery-eureka-0.0.1-SNAPSHOT.jar所在的目录创建Dockerfile文件,内容如下
FROM java:8
VOLUME /tmp
ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8761
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
四 使用docker build命令构建镜像
[root@master eureka]# docker build -t cakin24/microservice-discovery-eureka-0.0.1 .
Sending build context to Docker daemon 41.93MB
Step 1/6 : FROM java:8
8: Pulling from library/java
5040bd298390: Already exists
fce5728aad85: Already exists
76610ec20bf5: Already exists
60170fec2151: Already exists
e98f73de8f0d: Already exists
11f7af24ed9c: Already exists
49e2d6393f32: Already exists
bb9cdec9c7f3: Already exists
Digest: sha256:34959eed5df6bfe74a17fbf459ed29505d51a48d5cb4a39f215b613c65b8023b
Status: Downloaded newer image for java:8
---> d23bdf5b1b1b
Step 2/6 : VOLUME /tmp
---> Running in 4785be48986a
Removing intermediate container 4785be48986a
---> 86fe99594982
Step 3/6 : ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
---> c83cc2d01b55
Step 4/6 : RUN bash -c 'touch /app.jar'
---> Running in aa3d36c5e94b
Removing intermediate container aa3d36c5e94b
---> f327c892e271
Step 5/6 : EXPOSE 8761
---> Running in 801588962e36
Removing intermediate container 801588962e36
---> 12286992db9e
Step 6/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
---> Running in ebf934454742
Removing intermediate container ebf934454742
---> c635cec1377e
Successfully built c635cec1377e
Successfully tagged cakin24/microservice-discovery-eureka-0.0.1:latest
五 测试
1 启动镜像
[root@master eureka]# docker run -d -p 8761:8761 cakin24/microservice-discovery-eureka-0.0.1
465d4505708fd374bb90b6d6957bb398c42dba8f6d445de9aaef27b076d75377
2 访问
http://192.168.0.102:8761/
六 推动镜像到Docker Hub
[root@master eureka]# docker push cakin24/microservice-discovery-eureka-0.0.1
The push refers to repository [docker.io/cakin24/microservice-discovery-eureka-0.0.1]
eba923816d0c: Pushed
2fef467bbf84: Pushed
35c20f26d188: Mounted from library/java
c3fe59dd9556: Mounted from library/java
6ed1a81ba5b6: Mounted from library/java
a3483ce177ce: Mounted from library/java
ce6c8756685b: Mounted from library/java
30339f20ced0: Mounted from library/java
0eb22bfb707d: Mounted from library/java
a2ae92ffcd29: Mounted from library/java
latest: digest: sha256:5e9bb41ca606fe6a6bdfd3b7e871ee67d6438583febb0fc233b29ceccbd559fe size: 2424
【转载】原文地址:
https://blog.csdn.net/chengqiuming/article/details/80951472
作者:
wuqiong
时间:
2018-7-13 11:28
作者:
不二晨
时间:
2018-7-16 11:53
奈斯
作者:
吴琼老师
时间:
2018-7-18 14:56
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2