docker compose配置 network 指定ip
作者:我就是个世界
发表于:2025-01-01
version: '3.1' services: redis: image: redis container_name: redis restart: always networks: mynetwork: ipv4_address: 172.22.0.25 ports: - '6379:6379' volumes: - '/data/redis/conf/redis.conf:/etc/redis/conf/redis.conf' - '/data/redis/data:/data' - '/data/redis/log/redis.log:/etc/redis.log' environment: - 'TZ=Asia/Shanghai' networks: mynetwork: driver: bridge ipam: config: - subnet: 172.22.0.0/16 # 子网
1、只有自定义网络,才能手工指定每个容器的ip。默认的bridge是不行的!
2、手工设定了网段比如172.19.0.0 不影响docker在host装的网卡docker0 的172.17.0.1
容器内的172.19.0.XX 还是可以通过172.17.0.1访问到主机。
参考:
1. docker-compose.yml 参考官网 https://docs.docker.com/compose/compose-file/#network-configuration-reference
2. docker-compose配置networks https://www.cnblogs.com/youxin/p/17808800.html
3. docker-compose 手工指定容器IP https://www.cnblogs.com/xuanmanstein/p/10576476.html
请发表您的评论