(CC - 23) Lab 5

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

Cloud Computing

Lab 5
Agenda

• Getting a Shell Inside Containers


• Docker Networks
• Docker Networks CLI Management
• DNS and How Containers Find Each Other
Getting a Shell Inside Containers

docker container run -it


Start new container interactively.
docker container exec -it
Run command (additional command) in existing container.
• -t  pseudo-tty
▪ Simulates a real terminal, like what SSH does.
• -i  interactive
▪ Keep session open to receive terminal input.
Getting a Shell Inside Containers

DEMO
Demo: Getting a Shell Inside Containers
$ docker container run –it --name webserver nginx bash
# write exit to exit the container’s shell.

$ docker container ls  webserver will not be listed


$ docker container ls -a  List all containers. (notice COMMAND of webserver
and the other default nginx containers)

$ docker container run –it --name ubuntu-os ubuntu  -it option will get you
inside the container. then, we will install nano text editor inside the
container
$ root@9f23704290ae:/# apt-get update && apt-get install nano –y
$ root@9f23704290ae:/# nano test.txt  will open test.txt file for edit
# write any text inside the file press CTRL+O to save then CTRL-X to exit the
editor
# try to open it again to check if your data is saved

$ docker container run -d -p 3306:3306 --name db -e


MYSQL_RANDOM_ROOT_PASSWORD=yes mysql
$ docker container exec -it db bash
Docker Networks

• Each container connected to a private virtual


network "bridge"
• Each virtual network routes through NAT
firewall on host IP.
• All containers on a virtual network can talk to
each other without -p
Docker Networks

• Best practice is to create a new virtual


network for each app.
• For example:
▪ Network "my_web_app" for mysql and
php/apache containers.
▪ Network "my_api" for mongo and nodejs
containers.
Docker Networks (Cont.)

• "Batteries Included, But Removable"


▪ Defaults work well in many cases, but easy to
swap out parts to customize it.
• We can create new virtual networks.
• Attach containers to zero or more then one
virtual network.
• Skip virtual networks and use host IP (--
net=host).
Docker Networks CLI Management
$ docker network ls  Display networks.
$ docker network inspect  Inspect a network.
$ docker network create --driver  Create a
network.
$ docker network connect  Attach a network to
container.
$ docker network disconnect  Detach a network to
container.
Docker Networks: DNS (Cont.)

• Containers shouldn't rely on IP's for inter-


communication
• DNS for friendly names is built-in if you use
custom networks.
• The default bridge network doesn't have the
DNS server built into it by default.
▪ We can use --link option to specify manual
links between containers.
Demo: DNS and How Containers Find Each Other
$ docker network ls
$ docker network inspect bridge  to see containers attached to that network
(you should see webserver that was previously created)

$ docker network create my_app_net  spawns a new virtual network to attach


containers to
$ docker container run -d --name new_nginx --network my_app_net nginx
$ docker network inspect my_app_network
$ docker network connect my_app_network webserver  Dynamically creates a NIC
in a container on an existing virtual network
$ docker container inspect webserver  check networks that container is
connected to
$ docker container exec -it webserver ping new_nginx #or vice versa

$ docker network disconnect my_app_network webserver  Dynamically removes a


NIC in a container on a specific virtual network
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy