• 启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default networkdocker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network
  • 从报错信息看是不属于默认网络
  • 分析容器网络

    • 通过docker inspect 容器id 先后查看应用容器更新之前网络、报错应用容器网络、mysql容器网络、redis容器网络

      • 发现应用容器更新之前的gateway都为172.18.0.1

         docker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network

      • 报错应用容器网络的网关为172.17.0.1

        docker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network

    • 由上步得知,网络确实不一致,需要修改默认网络

      • 先查找容器内网络信息docker network ls

        docker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network

    • 接下来查看具体的网络信息docker network inspect 网络id

      • bridge网络截图

        docker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network

      • local_default 截图

        docker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network

  • 接下来创建时指定网络

    docker run -id --name  miaosha3.1    -p 7080:7080   --net="local_default"  --link mysql  \ 
    --link rabbitmq --link redis:myRedis \
    -v /etc/localtime:/etc/localtime:ro \
    镜像地址不写了
    • --net="link使用的网络"
  • 成功解决

  docker启动创建容器时,报错Cannot link to /mysql, as it does not belong to the default network