zoukankan      html  css  js  c++  java
  • [Docker] Allow Containers to Communicate through Docker Networks

    Docker containers that are running on your local machine can't communicate with each other. In this mini post explains why and shows a demonstration of Docker networks.

    Create two containers:

    docker run -it -d --rm --name one alpine /bin/sh
    docker run -it -d --rm --name two alpine /bin/sh  
    
    // -it -d: run in interactive mode and in background
    // once container is running, enter /bin/sh mode
    // use apline as base image 

    Entering 'one' container and run /bin/sh

    docker exec -it one /bin/sh

    If you try to ping container 'two', you will get a bad address error, because two containers are isolated.

    ping two

    Run:

    exit
    docker stop one
    docker stop two

    In order to let two container talk to each other, we need 'network':

    docker network create alpine-network

    Add two containers into network:

    docker run -it -d --rm --name one --network alpine-network alpine /bin/sh
    docker run -it -d --rm --name two --network alpine-network alpine /bin/sh

    You can see the configurations:

    docker network inspect alpine-network

    Entering one container:

    docker exec -it one /bin/sh
    ping two

    Now two container should be able to communicate each other

  • 相关阅读:
    搭建Git服务器
    shell脚本的使用
    谈谈递归和回溯算法的运用
    给 Qt 添加模块
    QtQuick 中的 qml 与 Qt 的 C++
    QT 中使用 c++ 的指针
    QT 的使用及编写代码遇到的问题和解决方法
    Centos 7 上安装使用 vscode
    PHP 数组转json格式,key的保存问题
    PHP compact
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14353410.html
Copyright © 2011-2022 走看看