设置docker compose的COMPOSE_PROJECT_NAME环境变量时,在有多个单词时,尽量不要使用下划线,因为COMPOSE_PROJECT_NAME会作为container_name的一部分。 而container_name在容器网络中会作为“域名”。而域名,是不接受非ldh ascii字符的,即不接受下划线。
例如在创建es容器,并通过域名尝试建立HTTPS连接,就会出现这样的报错了
{"@timestamp":"2023-03-09T11:58:44.679Z", "log.level": "WARN", "message":"caught exception while handling client http traffic, closing connection Netty4HttpChannel{localAddress=/172.18.0.4:9200, remoteAddress=/172.18.0.3:39554}", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"elasticsearch[es01][transport_worker][T#2]","log.logger":"org.elasticsearch.http.AbstractHttpServerTransport","elasticsearch.cluster.uuid":"RrJ6TQBKTFOfPOhRpnwR3w","elasticsearch.node.id":"d_QUqkLVSPqnRduAgFH6gQ","elasticsearch.node.name":"es01","elasticsearch.cluster.name":"es-cluster","error.type":"io.netty.handler.codec.DecoderException","error.message":"javax.net.ssl.SSLProtocolException: Illegal server name, type=host_name(0), name=xxxx_cloud_es8-es01, value={616E746979726173705F636C6F75645F6573382D65733031}","error.stack_trace":"io.netty.handler.codec.DecoderException: javax.net.ssl.SSLProtocolException: Illegal server name, type=host_name(0), name=xxxx_cloud_es8-es01, value={616E746979726173705F636C6F75645F6573382D65733031}\n\tat io.netty.codec@4.1.84.Final/io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:489)\n\tat io.netty.codec@4.1.84.Final/io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:280)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.DefaultChannelPipeline
NioByteUnsafe.read(AbstractNioByteChannel.java:166)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:689)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:652)\n\tat io.netty.transport@4.1.84.Final/io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)\n\tat io.netty.common@4.1.84.Final/io.netty.util.concurrent.SingleThreadEventExecutor
2.run(ThreadExecutorMap.java:74)\n\tat java.base/java.lang.Thread.run(Thread.java:1589)\nCaused by: javax.net.ssl.SSLProtocolException: Illegal server name, type=host_name(0), name=xxxx_cloud_es8-es01, value={616E746979726173705F636C6F75645F6573382D65733031}\n\tat java.base/sun.security.ssl.ServerNameExtension
CHServerNameConsumer.consume(ServerNameExtension.java:297)\n\tat java.base/sun.security.ssl.SSLExtension.consumeOnLoad(SSLExtension.java:609)\n\tat java.base/sun.security.ssl.SSLExtensions.consumeOnLoad(SSLExtensions.java:201)\n\tat java.base/sun.security.ssl.ClientHello
ClientHelloConsumer.onClientHello(ClientHello.java:840)\n\tat java.base/sun.security.ssl.ClientHello
DelegatedTask
DelegatedTask
DelegatedTask.run(SSLEngineImpl.java:1205)\n\tat io.netty.handler@4.1.84.Final/io.netty.handler.ssl.SslHandler.runDelegatedTasks(SslHandler.java:1549)\n\tat io.netty.handler@4.1.84.Final/io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1395)\n\tat io.netty.handler@4.1.84.Final/io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1236)\n\tat io.netty.handler@4.1.84.Final/io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1285)\n\tat io.netty.codec@4.1.84.Final/io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:519)\n\tat io.netty.codec@4.1.84.Final/io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:458)\n\t... 16 more\nCaused by: java.lang.IllegalArgumentException: The encoded server name value is invalid\n\tat java.base/javax.net.ssl.SNIHostName.<init>(SNIHostName.java:180)\n\tat java.base/sun.security.ssl.ServerNameExtension$CHServerNamesSpec.<init>(ServerNameExtension.java:131)\n\t... 34 more\nCaused by: java.lang.IllegalArgumentException: Contains non-LDH ASCII characters\n\tat java.base/java.net.IDN.toASCIIInternal(IDN.java:292)\n\tat java.base/java.net.IDN.toASCII(IDN.java:122)\n\tat java.base/javax.net.ssl.SNIHostName.<init>(SNIHostName.java:176)\n\t... 35 more\n"}
但离谱的是,似乎docker有建议使用下划线来命名COMPOSE_PROJECT_NAME,并且你也无法用大小写来区分,之后会都转换为小写的。