카타코더 Docker - Creating Networks Between Containers using Networks

1 개요[ | ]

카타코더 Docker - Creating Networks Between Containers using Links
카타코더 Docker - Communicating Between Containers
카타코더 Docker
# 🔗 제목
카타코더 Docker/1 e
🡵 카타코더 Docker - Deploying Your First Docker Container
🡵 카타코더 Docker - Deploy Static HTML Website as Container
🡵 카타코더 Docker - Building Container Images
🡵 카타코더 Docker - Dockerizing Node.js
🡵 카타코더 Docker - Optimise Builds With Docker OnBuild
🡵 카타코더 Docker - Ignoring Files During Build
🡵 카타코더 Docker - Create Data Containers
🡵 카타코더 Docker - Creating Networks Between Containers using Links
🡵 카타코더 Docker - Creating Networks Between Containers using Networks
🡵 카타코더 Docker - Persisting Data Using Volumes

2 Create Network[ | ]

$ docker network create backend-network
46c8cf526f4ae7a5f575aded1b8095ce88baf1c13eef8df45d49ab1e2af79eba
$ docker run -d --name=redis --net=backend-network redis
d41b57a9f62078640edb5f0801252a7be58a20d40a2db4c4d378b6cecdb9ef2a

3 Network Communication[ | ]

$ docker run --net=backend-network alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=85911d7053d5
HOME=/root
$ docker run --net=backend-network alpine cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.19.0.3      76eb28d6440e
$ docker run --net=backend-network alpine cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0
$ docker run --net=backend-network alpine ping -c1 redis
PING redis (172.19.0.2): 56 data bytes
64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.086 ms

--- redis ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.086/0.086/0.086 ms

4 Connect Two Containers[ | ]

$ docker network create frontend-network
db2460f2204679978304c75175c87d3d65495f379b07216aec5f2d0ce4a25d2f
$ docker network connect frontend-network redis
$ docker run -d -p 3000:3000 --net=frontend-network katacoda/redis-node-docker-example
Unable to find image 'katacoda/redis-node-docker-example:latest' locally
latest: Pulling from katacoda/redis-node-docker-example
12b41071e6ce: Pull complete
a3ed95caeb02: Pull complete
49a025abf7e3: Pull complete
1fb1c0be01ab: Pull complete
ae8c1f781cde: Pull complete
db73207ad2ae: Pull complete
446b13034c13: Pull complete
Digest: sha256:1aae9759464f00953c8e078a0e0d0649622fef9dd5655b1491f9ee589ae904b4
Status: Downloaded newer image for katacoda/redis-node-docker-example:latest
135c7b499f973fc7a34da55479400358af0031f07b8e8585c75d78bc65be6cb0
$ curl docker:3000
This page was generated after talking to redis.

Application Build: 1

Total requests: 1

IP count:
    ::ffff:172.17.0.72: 1

5 Create Aliases[ | ]

$ docker network create frontend-network2
281ebc5c15a4066c513e0d8f716b2f97c59388cdc0c6cd64feadeb4fa125c7c2
$ docker network connect --alias db frontend-network2 redis
$ docker run --net=frontend-network2 alpine ping -c1 db
PING db (172.21.0.2): 56 data bytes
64 bytes from 172.21.0.2: seq=0 ttl=64 time=0.086 ms

--- db ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.086/0.086/0.086 ms

6 Disconnect Containers[ | ]

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
46c8cf526f4a        backend-network     bridge              local
88d8d238f516        bridge              bridge              local
db2460f22046        frontend-network    bridge              local
281ebc5c15a4        frontend-network2   bridge              local
fa054a9af353        host                host                local
f50397115ef2        none                null                local
$ docker network inspect frontend-network
[
    {
        "Name": "frontend-network",
        "Id": "db2460f2204679978304c75175c87d3d65495f379b07216aec5f2d0ce4a25d2f",
        "Created": "2019-03-23T10:47:49.353654446Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "135c7b499f973fc7a34da55479400358af0031f07b8e8585c75d78bc65be6cb0": {
                "Name": "practical_nobel",
                "EndpointID": "623b5ad7f3597ef573d62b9b0457a4b6ea786fa26a73446b88e4c9fadafa1652",
                "MacAddress": "02:42:ac:14:00:03",
                "IPv4Address": "172.20.0.3/16",
                "IPv6Address": ""
            },
            "d41b57a9f62078640edb5f0801252a7be58a20d40a2db4c4d378b6cecdb9ef2a": {
                "Name": "redis",
                "EndpointID": "6a8dea6a9c778bf08a22ef02767104e1cd92c9d9f8070fe6261bfac11a15b63c",
                "MacAddress": "02:42:ac:14:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]
$ docker network disconnect frontend-network redis
$
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}