[Docker] - implementations access each other between different containers (e.g.: Client Access DB)

Deployed two separate containers:

Container #1 - Web Client
Container #2 - SQL Server

How different containers visits?

Not available from Container # 1 to Container # 2, ping nowhere. 

Check the network status

When installing Docker, automatically creates three networks.

docker network ls command lists these networks.

bridge network: that all Docker docker0 network installations are present. Unless docker run --net = <NETWORK> option otherwise specified, the default daemon will Docker container connected to this network by default. Use ifconfig command on the host, you can see that this bridge is part of the network stack of host.
none network: In one particular container is added to a network stack on the container. The container is missing network interface.
host network: add a container on the host network stack. You can find the container network configuration with the same host.

docker network inspect command to display details of one or more networks.

It returns information about one or more networks. By default, this command all results are presented in a JSON object.

docker network ls

NETWORK ID          NAME              DRIVER 
7fca4eb8c647        bridge            bridge 
9f904ee27bf5        none              null 
cf03ee007fb4        host              host

docker network inspect bridge
[ { "Name": "bridge", "Id": "b2c85e46cb4fad5603c1614d04e73f6fc07a27b0d4c6a026f03b28a50a6e869b", "Created": "2019-11-03T09:14:31.8501331Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "0d5338cf858f58e6dcffa489229d1b2f2b35cdc6ce3076bd2eccba305186dce9": { "Name": "exciting_perlman", "EndpointID": "48aca2d7558edf69d1e6bfbcb6c47f4f3446d64e278600ffaf8a9b47cf7e60c2", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ]

Issue reason

Container # 1 contained in the bridge network, the Container # 2 has not been included.

solution

Restart container, # 1 to # 2 in the same access network ( Bridge ) can be.

docker run --name mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-CTP3.2-ubuntu

docker ps

docker network connect bridge 4f91e220c912

docker network inspect bridge
[
    {
        ......"ConfigOnly": false,
        "Containers": {
            "0d5338cf858f58e6dcffa489229d1b2f2b35cdc6ce3076bd2eccba305186dce9": {
                "Name": "exciting_perlman",
                "EndpointID": "48aca2d7558edf69d1e6bfbcb6c47f4f3446d64e278600ffaf8a9b47cf7e60c2",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },
            "4f91e220c9126a443143d7e98f2bc8afdbd82211402c581a6a411c197a77ea25": {
                "Name": "mssql",
                "EndpointID": "050fc8a64e774480e8728292d14778ba86beea433e37ca28cd03414de000f739",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        ......
    }
]

 

How to use ifconfig and ping command at Docker's Ubuntu mirror?

Docker into the container

docker exec -it ID container or container name bash

Installation ifconfig and ping Kit

apt-get update
apt-get install net-tools
apt-get install iputils-ping

 

Docker normal operation command?

Start container

docker start container or container name ID

Parameters
-i: Start in interactive mode
-t: in order to process additional way to start

Stop the container

docker stop container or container name ID

Parameters
-t: closed container limit, if the timeout fails to shut down the kill with a forced shutdown, the default value is 10s, this time for a container of their own state of preservation

Closed container

Docker the kill container or container name ID

Restart container

docker restart container or container name ID

Parameters
-t: closed container limit, if the timeout fails to shut down the kill with a forced shutdown, the default value is 10s, this time for a container of their own state of preservation

 

Reference material

https://www.cnblogs.com/lihan829/p/11483594.html
https://forums.docker.com/t/how-to-reach-a-container-from-another-container-without-ip-of-dockernat/21083/4
https://www.ibm.com/developerworks/cn/linux/l-docker-network/index.html
https://www.cnblogs.com/jsonhc/p/7823286.html
https://www.yiibai.com/docker/network_connect.html
https://blog.csdn.net/Michel4Liu/article/details/80889977

Guess you like

Origin www.cnblogs.com/jinzesudawei/p/11790038.html