使用Jenkins打包docker镜像时报这个错,并且还是在有别的项目正常打包的情况下,新建的任务就不好使了。
完整的错误信息:
[Docker] ERROR: Failed to exec start:null
[Docker] ERROR: Failed to create docker image: org.apache.http.client.ClientProtocolException
ERROR: Build step failed with exception
java.net.SocketException: Broken pipe (Write failed)
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124)
at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:136)
at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:167)
at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:179)
at org.apache.http.impl.io.SessionOutputBufferImpl.writeLine(SessionOutputBufferImpl.java:219)
at org.apache.http.impl.io.ChunkedOutputStream.flushCacheWithAppend(ChunkedOutputStream.java:123)
at org.apache.http.impl.io.ChunkedOutputStream.write(ChunkedOutputStream.java:179)
at org.glassfish.jersey.message.internal.CommittingOutputStream.write(CommittingOutputStream.java:229)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$UnCloseableOutputStream.write(WriterInterceptorExecutor.java:299)
at org.glassfish.jersey.message.internal.ReaderWriter.writeTo(ReaderWriter.java:116)
at org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider.writeTo(AbstractMessageReaderWriterProvider.java:79)
at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:105)
at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:60)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at com.github.dockerjava.jaxrs.filter.LoggingFilter.aroundWriteTo(LoggingFilter.java:300)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
at org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:517)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499)
at org.glassfish.jersey.apache.connector.ApacheConnector$2.writeTo(ApacheConnector.java:583)
at org.apache.http.impl.execchain.RequestEntityProxy.writeTo(RequestEntityProxy.java:121)
at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156)
at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:152)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
Caused: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
Caused: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused: java.lang.RuntimeException
at com.google.common.base.Throwables.propagate(Throwables.java:156)
at com.github.dockerjava.core.async.ResultCallbackTemplate.getFirstError(ResultCallbackTemplate.java:133)
at com.github.dockerjava.core.async.ResultCallbackTemplate.awaitCompletion(ResultCallbackTemplate.java:94)
at com.github.dockerjava.core.command.BuildImageResultCallback.awaitImageId(BuildImageResultCallback.java:46)
at org.jenkinsci.plugins.dockerbuildstep.cmd.remote.CreateImageRemoteCallable.call(CreateImageRemoteCallable.java:105)
at org.jenkinsci.plugins.dockerbuildstep.cmd.remote.CreateImageRemoteCallable.call(CreateImageRemoteCallable.java:29)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at org.jenkinsci.plugins.dockerbuildstep.cmd.CreateImageCommand.execute(CreateImageCommand.java:115)
Caused: java.lang.IllegalArgumentException
at org.jenkinsci.plugins.dockerbuildstep.cmd.CreateImageCommand.execute(CreateImageCommand.java:119)
at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder.perform(DockerBuilder.java:77)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.build(MavenModuleSetBuild.java:944)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:894)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1856)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Build step 'Execute Docker command' marked build as failure
[Checks API] No suitable checks publisher found.
Finished: FAILURE
产生此异常的原因就是因为Jenkins创建任务的时候,任务名中包含了大写字母或者是DockerFile里面配置的镜像名称和路径跟任务配置中的不一致。
第一点,看这里,这个任务名称,不能包含大写字母。
你要说不支持大写字母,Jenkins 在创建任务的时候,就该提示了对吧,其实并没有,因为这个不是Jenkins的锅,因为使用maven打包项目也是正常的。
那么问题在哪呢?????? rnmmp,我找了一上午,没找到在哪。。。。。。。
最后实在没办法了,我直接在项目文件夹下手动执行构建镜像,也就是使用docker build
看下操作日志:
[root@docker-manager-40-37 providerB]# ls
Dockerfile pom.xml src target
[root@docker-manager-40-37 providerB]# pwd
/usr/soft/jenkins_home/workspace/providerB
[root@docker-manager-40-37 providerB]# ll
总用量 12
-rw-r--r--. 1 1000 1000 543 10月 28 11:50 Dockerfile
-rw-r--r--. 1 1000 1000 4405 10月 28 11:50 pom.xml
drwxr-xr-x. 5 1000 1000 42 10月 28 11:14 src
drwxr-xr-x. 6 1000 1000 169 10月 28 11:50 target
[root@docker-manager-40-37 providerB]# docker build -t 192.168.40.37:5000/jadl/providerB:1.0_$BUILD_NUMBER
invalid argument "192.168.40.37:5000/jadl/providerB:1.0_" for "-t, --tag" flag: invalid reference format: repository name must be lowercase
See 'docker build --help'.
[root@docker-manager-40-37 providerB]# docker build -t 192.168.40.37:5000/jadl/providerB:1.0_t0
invalid argument "192.168.40.37:5000/jadl/providerB:1.0_t0" for "-t, --tag" flag: invalid reference format: repository name must be lowercase
See 'docker build --help'.
[root@docker-manager-40-37 providerB]# docker build -t 192.168.40.37:5000/jadl/providerb:1.0_t0
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
[root@docker-manager-40-37 providerB]# docker images
这里面非常非常关键的一个提醒就是:repository name must be lowercase
,镜像仓库里面的镜像名称必须为小写字母
,就很迷???是不是。。。。
但是呢,我执行完之后,并没有在意,因为到中午吃饭时间了。。。。。
午休过后,又开始倒腾这个,然后发现这个路径的名称是包含大写字母的,试着改一下吧,改成小写的,将providerB
改为 provider_b
, 顺带把任务里面的配置也给一块改了。
以及Dockerfile里面的jar的名称,也给改成下划线的了。
再次构建,竟然好了????困扰一上午了。。。。