运行中的docker配置端口映射(添加/删除)

  • 添加端口映射

    
    a, 获取容器ip  
        docker inspect $container_name | grep IPAddress
    b. 添加转发规则  
        iptables -t nat -A DOCKER -p tcp --dport $host_port -j DNAT --to-destination $docker_ip:$docker_port  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 删除端口映射规则

    a. 获取规则编号  
        iptables -t nat -nL --line-number
    b. 根据编号删除规则  
        iptables -t nat -D DOCKER $num
    
    • 1
    • 2
    • 3
    • 4
    • 5

猜你喜欢

转载自blog.csdn.net/weixin_37773766/article/details/80741770