Esercizio 2: comunicazione con host

02net1-ccli-chttp

Una rete, client e server HTTP.

Collegamento a server HTTP dal browser dello host.

02net

Scaffolding

Creare la directory di progetto:

mkdir 02net1-ccli-chttp
cd 02net1-ccli-chttp

Preparare lo scaffolding. Il risultato è:

.
├── ccli
│   └── Dockerfile
├── chttp
└── docker-compose.yml

Il file ccli/Dockerfile è lo stesso dell’esercizio precedente°

cp ../01net1-ccli-cssh/ccli/Dockerfile ccli

Il server HTTP userà un’immagine dal Docker Hub, non vi sarà bisogno di costruirne una.

docker-compose.yml

vim docker-compose.yml
version: '3.6'

services:
  one:
    build: ccli
    image: ccli
    container_name: one
    hostname: one
    cap_add:
      - ALL
    networks:
      net1:
        ipv4_address: 192.168.101.11
  two:
    image: httpd:2.4-alpine
    container_name: two
    hostname: two
    cap_add:
      - ALL
    networks:
      net1:
        ipv4_address: 192.168.101.12
networks:
  net1:
    name: net1
    ipam:
      driver: default
      config:
        - subnet: 192.168.101.0/24

Lancio

Term10

Accesso da Browser esterno

Occorre compiere un port mapping.

Modificare docker-compose.yml per supportarlo:

...
  two:
    image: httpd:2.4-alpine
    container_name: two
    hostname: two
    cap_add:
      - ALL
    ports:
      - 8888:80
    networks:
      net1:
        ipv4_address: 192.168.101.12

...

Esecuzione

Partenza del progetto:

docker-compose up -d

Aprire un browser sulla macchina virtuale.

Collegarsi a http://localhost:8888 e verificare.

Term11

Esercizio 2A

Una rete, client e server HTTP.

Da tcpdump di un container a Wireshark sullo host.

Term12

Cooperazione tra Host e Container

Installare Wireshark sulla macchina host:

sudo apt install wireshark-qt

Richiede tempo.

Far partire il progetto:

docker-compose up -d

Dalla macchina host:

Lanciare Wireshark che si collega al tcpdump del container one

sudo wireshark -i <(docker exec one tcpdump -i eth0)

Qualsiasi interfaccia vethxxx va bene.

Su one:

Aprire un terminale.

Collegarsi al server HTTP con curl:

curl -v http://two

Monitorare il traffico su Wireshark.