docker network的alias可以理解为同一个网络下的ip,同一个网络的容器可以通过alias调用目标容器:
比如容器A的别名是aliasA,那么容器B要调用容器A的一个http端口,可以这样:
http://aliasA:端口号
docker-compose会默认将当前的容器名称作为network的alias,如果想设置其他alias:文章来源:https://www.toymoban.com/news/detail-617015.html
test-cloud-nacos:
image: nacos/nacos-server:latest
environment:
- JVM_XMS=1024m
- JVM_XMX=2048m
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=derby
ports:
- 8748:8848
- 9748:9848
- 9749:9849
restart: always
networks:
net_name:
ipv4_address: ${intple_cloud_nacos_default:-124.81.62.30}
aliases:
- test-cloud-nacos-2
通过docker inspect test-test-cloud-nacos-1 可以查看到最终的结果:文章来源地址https://www.toymoban.com/news/detail-617015.html
"Networks": {
"net_name": {
"IPAMConfig": {
"IPv4Address": "124.81.62.30"
},
"Links": null,
"Aliases": [
"test-test-cloud-nacos-1",
"test-cloud-nacos",
"test-cloud-haha",
"70b0732f2d9a"
],
"NetworkID": "0ff90e8a8bd8d8fc350f8db0a8c7c813cd522db619a079ddcb61affa7e294704",
"EndpointID": "6871010aacec518a5248dd634fae761ba747607101230c69523e89eec771d86d",
"Gateway": "124.81.62.1",
"IPAddress": "124.81.62.30",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:7c:51:3e:1e",
"DriverOpts": null
}
}
到了这里,关于docker-compose设置network的alias的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!