Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Container Network LAB

Table of contents
  1. Container Network LAB
    1. LAB 1. Docker0 network
      1. Configure containers and networks like below
      2. Required Satisfaction Conditions
        1. Buiding Step
        2. IP check
      3. Create container with reference to the following conditions
        1. Building step
      4. Q. How to know container web’s IP
    2. LAB 2. Port-Forwarding
      1. O. Run 3 containers by the following below condition.
      2. A. Building Step
    3. LAB 3. Creating User-Defined Network
      1. Q. Create a network for use at containers by following the below conditions
      2. A. Building step
      3. Check

LAB 1. Docker0 network

Configure containers and networks like below

1

Required Satisfaction Conditions

  • Container image: busybox:latest
  • Connet to inside with creating a container
  • CMD [“sh”]
  • Check those’s IP

Buiding Step

  • C1
    $ docker run –name C1 -d -it –rm busybox:latest
    2
  • C2
    $ docker run –name C2 -d -it –rm busybox:latest
    3

IP check

  • C1
    $ docker attach C1 / # ifconfig 4

  • C2
    $ docker attach C2 / # ifconfig 5

Create container with reference to the following conditions

  • Container name: web
  • Container image: nginx:latest
  • Port-forwarding: Port 80
  • Background-Activating

Building step

  • $ docker run -d –name web -p 80:80 nginx:latest
  • -d : background-activating
  • –name: container name
  • -p : port-forwarding
    6

Q. How to know container web’s IP

  • $ docker inspect web
    7 8
  • You can check docker0’s role as a gateway in the container network.

LAB 2. Port-Forwarding

O. Run 3 containers by the following below condition.

  • Web1
    - Container image: nginx:latest - Container name: web1
    - Background-Activating
    - Insert command : -p 80:80

  • Web2
    - Container image: nginx:latest - Container name: web2
    - Background-Activating
    - Insert : -p 80

  • Web3
    - Container image: nginx:latest - Container name: web3
    - Background-Activating
    - Insert : -P

A. Building Step

  • Web1
    $ docker run –name web1 -d -p 80:80 nginx:latest
  • Web2
    $ docker run –name web2 -d -p 80 nginx:latest
  • web3
    $ docker run –name web3 -d -P
    9

LAB 3. Creating User-Defined Network

Q. Create a network for use at containers by following the below conditions

  • subnet: 192.168.1.0/24
  • gateway: 192.168.1.254
  • network name : cloudnet

A. Building step

    ```
    $ docker network create --driver bridge \
    --subnet 192.168.1.0/24 \
    --gateway 192.168.1.254 \
    ```

10

Check

11


Table of contents