微服务之路--服务注册中心-docker云化

上一篇文章我们讲解了如果构建一个服务注册中心,今天我们将服务中心打一个镜像推送到docker仓库

1.打开工程pom所在目录,然后在当前目录下打开命令窗口,在命令窗口下执行mvn docker:build

最终显示成功如下:

$ mvn docker:build
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.bob.soft:mic-service-eureka >-------------------
[INFO] Building mic-service-eureka 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- docker-maven-plugin:0.4.10:build (default-cli) @ mic-service-eureka ---
[INFO] Copying D:\workspace-bob\micservice\target\mic-service-eureka.jar -> D:\workspace-bob\micservice\target\docker\mic-service-eureka.jar
[INFO] Copying D:\workspace-bob\micservice\target\classes\application.properties -> D:\workspace-bob\micservice\target\docker\application.properties
[INFO] Copying D:\workspace-bob\micservice\target\classes\com\bob\soft\micservice\servicecenter\EurekaApplication.class -> D:\workspace-bob\micservice\target\docker\com\bob\soft\micservice\servicecenter\EurekaApplication.class
[INFO] Copying D:\workspace-bob\micservice\target\classes\Dockerfile -> D:\workspace-bob\micservice\target\docker\Dockerfile
[INFO] Building image 47.93.222.240:5000/com.bob.soft/mic-service-eureka:1.0-SNAPSHOT
Step 1/5 : FROM java:8
 ---> d23bdf5b1b1b
Step 2/5 : MAINTAINER "william"<952408421@qq.com>
 ---> Using cache
 ---> 45b439cdc0cb
Step 3/5 : ADD mic-service-eureka.jar app.jar
 ---> f51c0973d49b
Removing intermediate container ad180b959e9d
Step 4/5 : EXPOSE 8000
 ---> Running in c4d7ba02052e
 ---> e0e5a8b0d50f
Removing intermediate container c4d7ba02052e
Step 5/5 : CMD java -jar app.jar
 ---> Running in a747f2a6f77c
 ---> fdfadf43c5be
Removing intermediate container a747f2a6f77c
Successfully built fdfadf43c5be
[INFO] Built 47.93.222.240:5000/com.bob.soft/mic-service-eureka:1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.142 s
[INFO] Finished at: 2019-11-26T22:34:34+08:00
[INFO] ------------------------------------------------------------------------
 

你可能会碰到如下异常

1. 服务器端口未开放异常

vicecenter\EurekaApplication.class
[INFO] Copying D:\workspace-bob\micservice\target\classes\Dockerfile -> D:\workspace-bob\micservice\target\docker\Dockerfile
[INFO] Building image 47.93.222.240:5000/com.bob.soft/mic-service-eureka:1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.923 s
[INFO] Finished at: 2019-11-26T22:31:14+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.10:build (default-cli) on project mic-service-eureka: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect -> [Help 1]

解决,开放5000和2375 端口

问题2 docker未开启远程服务

解决:vi /usr/lib/systemd/system/docker.service

在[Service]部分的最下面添加下面两行:

ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

 

重启docker

systemctl daemon-reload
systemctl restart docker

 

问题3  docker缺乏代理

[root@iZ2zecja84ag27qwag75o9Z ~]# docker run -d -p 8001:8000 47.93.222.240:5000/com.bob.soft/mic-service-eureka:1.0-SNAPSHOT
4d380ed23e98fc38ccd0a3afe272122de302d4202c04422badf8af8abf159b53
/usr/bin/docker-current: Error response from daemon: driver failed programming external connectivity on endpoint kickass_feynman (3f24a94e9d2f65c3ff329c53cc9e3acef2b8543accb55b3d36af8cde31735
9c4): exec: "docker-proxy": executable file not found in $PATH.

解决:

cat /usr/lib/systemd/system/docker.service | grep prox
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \

# ln -s /usr/libexec/docker/docker-proxy-current /usr/bin/docker-proxy

问题4:docker 缺少运行的库

/usr/bin/docker-current: Error response from daemon: shim error: docker-runc not installed on system

解决方法:

     cd /usr/libexec/docker

     ln -s docker-runc-current docker-runc

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值