docker 容器固定ip 示例

version: '3'
services:
    nginx:
        image: nginx:latest
        # 端口映射
        ports:
            - "80:80"
        # 依赖关系 先跑php
        
        networks:
            - app_net
        # 容器名称
        container_name: "compose-nginx"
    
    mysql:
        image: mysql:5.7
        ports:
            - "3306:3306"
        # 环境变量
        environment:
            # mysql密码
            - MYSQL_ROOT_PASSWORD=123456
        networks:
            app_net:
                # 固定子网ip,网段必须在子网络10.10.*.*
                ipv4_address: 10.10.10.1
        container_name: "compose-mysql"
networks:
    # 配置docker network
    app_net:
        driver: bridge
        ipam:
            config:
                # 子网络
                - subnet: 10.10.0.0/16

  

posted @ 2022-04-26 09:05  dunkbird  阅读(132)  评论(0编辑  收藏  举报