Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corso_olss_2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arianna Carbone
corso_olss_2021
Commits
9707ac86
Commit
9707ac86
authored
3 years ago
by
Alessandro Costantini
Browse files
Options
Downloads
Patches
Plain Diff
Update docker_handson.md
parent
68b044e9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
containers/docker_handson.md
+125
-0
125 additions, 0 deletions
containers/docker_handson.md
with
125 additions
and
0 deletions
containers/docker_handson.md
+
125
−
0
View file @
9707ac86
...
...
@@ -447,6 +447,131 @@ volumes:
```
## Docker network
```
$ ip address show
...
$ docker run -it --network=none alpine /bin/sh
/ # ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
/ #
$ docker network
Usage: docker network COMMAND
Manage networks
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
Run 'docker network COMMAND --help' for more information on a command.
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
8cf72d5da8d9 bridge bridge local
77d5801c72d6 host host local
00059d5f3d9d minikube bridge local
9f01cae8edb7 none null local
$ docker run -td --name test1 alpine
$ docker run -td --name test2 alpine
$ docker exec -it test1 /bin/sh
/ # ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
306: eth0@if307: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # exit
$ docker exec -it test2 /bin/sh
/ # ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
308: eth0@if309: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.252 ms
64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.246 ms
64 bytes from 172.17.0.2: seq=2 ttl=64 time=0.230 ms
64 bytes from 172.17.0.2: seq=3 ttl=64 time=0.185 ms
64 bytes from 172.17.0.2: seq=4 ttl=64 time=0.173 ms
64 bytes from 172.17.0.2: seq=5 ttl=64 time=0.337 ms
^C
--- 172.17.0.2 ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 0.173/0.237/0.337 ms
/ # exit
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
8cf72d5da8d9 bridge bridge local
77d5801c72d6 host host local
00059d5f3d9d minikube bridge local
9f01cae8edb7 none null local
$ docker network create bridge1
21e98d5bc828cbc55ed90866bf93573b7677be433b2b03346f6e0a915d4b18fe
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
8cf72d5da8d9 bridge bridge local
21e98d5bc828 bridge1 bridge local
...
$ docker run -td --name test3 --network=bridge1 alpine
$ docker exec -it test3 /bin/sh
/ # ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
311: eth0@if312: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:c0:a8:f0:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.240.2/20 brd 192.168.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2): 56 data bytes
^C
--- 172.17.0.2 ping statistics ---
2 packets transmitted, 0 packets received, 100% packet loss
/ # ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3): 56 data bytes
^C
--- 172.17.0.3 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
$ docker network connect bridge test3
$ docker network inspect bridge
[
{
"Name": "bridge",
...
$ docker network inspect my-bridge | python -c "import sys, json; print([v['Name'] for k,v in json.load(sys.stdin)[0]['Containers'].items()])"
```
## Docker process management
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment