centos7下docker发布第一个微服务应用(Eureka)

2019-02-20 00:47:45来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

1.在windows下打包

微服务应用通过maven进行打包,在项目的pom.xml执行mvn clean package,或者直接通过idea或者eclipse进行maven打包

之上操作将在项目的 target目录生成文件microservice-discovery-eureka-0.0.1-SNAPSHOT.jar 包

2.将microservice-discovery-eureka-0.0.1-SNAPSHOT.jar拷贝到Linux环境(可以通过CRT等连接方式)

3.在microservice-discovery-eureka-0.0.1-SNAPSHOT.jar所在的目录创建Dockerfile文件,内容如下

 1 FROM java:8
 2 
 3 VOLUME /tmp
 4 
 5 ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
 6 
 7 RUN bash -c 'touch /app.jar'
 8 
 9 EXPOSE 8761
10 
11 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

 4.通过docker build命令构建新的镜像

(注意:Dockerfile和jar包要在同一个文件夹下)

 执行命令 docker build -t cakin24/microservice-discovery-eureka-0.0.1 .   

 1 [root@localhost microfile]# ls
 2 Dockerfile  microservice-discovery-eureka-0.0.1-SNAPSHOT.jar
 3 [root@localhost microfile]# docker build -t cakin24/microservice-discovery-eureka-0.0.1 .
 4 Sending build context to Docker daemon  44.79MB
 5 Step 1/6 : FROM java:8
 6 8: Pulling from library/java
 7 5040bd298390: Pull complete 
 8 fce5728aad85: Pull complete 
 9 76610ec20bf5: Pull complete 
10 60170fec2151: Pull complete 
11 e98f73de8f0d: Pull complete 
12 11f7af24ed9c: Pull complete 
13 49e2d6393f32: Pull complete 
14 bb9cdec9c7f3: Pull complete 
15 Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
16 Status: Downloaded newer image for java:8
17  ---> d23bdf5b1b1b
18 Step 2/6 : VOLUME /tmp
19  ---> Running in c6c8df634611
20 Removing intermediate container c6c8df634611
21  ---> 1bdb7dd203b9
22 Step 3/6 : ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
23  ---> d88f6144fb16
24 Step 4/6 : RUN bash -c 'touch /app.jar'
25  ---> Running in d217d42a3713
26 Removing intermediate container d217d42a3713
27  ---> b24c68563734
28 Step 5/6 : EXPOSE 8761
29  ---> Running in 2a2663de2b31
30 Removing intermediate container 2a2663de2b31
31  ---> 305d7a1bed02
32 Step 6/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
33  ---> Running in c7b7c777ee72
34 Removing intermediate container c7b7c777ee72
35  ---> 6e55e8eef9b1
36 Successfully built 6e55e8eef9b1
37 Successfully tagged cakin24/microservice-discovery-eureka-0.0.1:latest
38 [root@localhost microfile]# docker images
39 REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
40 cakin24/microservice-discovery-eureka-0.0.1          latest              6e55e8eef9b1        24 seconds ago      733MB
41 mysql                                                5.7                 e47e309f72c8        13 days ago         372MB
42 hello-world                                          latest              fce289e99eb9        7 weeks ago         1.84kB
43 java                                                 8                   d23bdf5b1b1b        2 years ago         643MB
44 registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql   5.7                 ec7e75e5260c        3 years ago         360MB

5.执行以下命令 运行微服务

查看镜像 docker images  通过上面步骤可以看到当前多了一个Eureka的镜像,这个就是我们想要的

运行容器 docker run -d -p 8761:8761 cakin24/microservice-discovery-eureka-0.0.1

查看已经运行的容器情况  docker ps   可以看到Eureka已经在运行当中

 1 [root@localhost microfile]# docker images
 2 REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
 3 cakin24/microservice-discovery-eureka-0.0.1          latest              6e55e8eef9b1        24 seconds ago      733MB
 4 mysql                                                5.7                 e47e309f72c8        13 days ago         372MB
 5 hello-world                                          latest              fce289e99eb9        7 weeks ago         1.84kB
 6 java                                                 8                   d23bdf5b1b1b        2 years ago         643MB
 7 registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql   5.7                 ec7e75e5260c        3 years ago         360MB
 8 [root@localhost microfile]# docker run -d -p 8761:8761 cakin24/microservice-discovery-eureka-0.0.1
 9 bc05ffb47756bc1193f71c668acd2ddb51392de883dba3d6f26a786723d78397
10 [root@localhost microfile]# docker ps
11 CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS              PORTS                               NAMES
12 bc05ffb47756        cakin24/microservice-discovery-eureka-0.0.1   "java -Djava.securit…"   11 seconds ago      Up 8 seconds        0.0.0.0:8761->8761/tcp              flamboyant_golick
13 e778509d7366        mysql:5.7                                     "docker-entrypoint.s…"   About an hour ago   Up About an hour    0.0.0.0:3306->3306/tcp, 33060/tcp   pwc-mysql

6.查看运行效果

 访问发布的容器对应的ip和端口 效果如下,

 


原文链接:https://www.cnblogs.com/zluckiy/p/10403654.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:1到100循环,并把奇数放到数组中,把偶数放到map中

下一篇:爸爸又给Spring MVC生了个弟弟叫Spring WebFlux