2021-10-31 19:51:17 +00:00
|
|
|
|
\newpage
|
|
|
|
|
|
2022-04-08 20:39:14 +00:00
|
|
|
|
::::: {.exercice}
|
|
|
|
|
|
|
|
|
|
`docker exec`
|
|
|
|
|
-------------
|
2017-11-09 00:30:41 +00:00
|
|
|
|
|
|
|
|
|
Après voir lu la partie concernant les *namespaces*, vous avez dû comprendre
|
|
|
|
|
qu'un `docker exec`, n'était donc rien de plus qu'un `nsenter(1)`.
|
|
|
|
|
|
2022-02-24 19:43:43 +00:00
|
|
|
|
Réécrivons, en quelques lignes, la commande `docker exec` !
|
2017-11-09 00:30:41 +00:00
|
|
|
|
|
2022-02-24 19:43:43 +00:00
|
|
|
|
Pour savoir si vous avez réussi, comparez les sorties des commandes :
|
2017-11-09 00:30:41 +00:00
|
|
|
|
|
2022-02-24 19:43:43 +00:00
|
|
|
|
- `ip address` ;
|
|
|
|
|
- `hostname` ;
|
|
|
|
|
- `mount` ;
|
|
|
|
|
- `ps -aux` ;
|
2017-11-09 00:30:41 +00:00
|
|
|
|
- ...
|
|
|
|
|
|
|
|
|
|
|
2019-11-03 17:54:22 +00:00
|
|
|
|
### Tests {-}
|
2017-11-09 00:30:41 +00:00
|
|
|
|
|
|
|
|
|
<div lang="en-US">
|
2018-11-16 01:38:41 +00:00
|
|
|
|
```
|
|
|
|
|
42sh$ docker run --name mywebserver -d -p 80:80 nginx
|
|
|
|
|
d63ceae863956f8312aca60b7a57fbcc1fdf679ae4c90c5d9455405005d4980a
|
|
|
|
|
42sh$ docker container inspect --format '{{ .State.Pid }}' mywebserver
|
|
|
|
|
234269
|
|
|
|
|
|
|
|
|
|
42sh# ./mydocker_exec mywebserver ip address
|
2022-02-24 19:43:43 +00:00
|
|
|
|
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group def
|
2018-11-16 01:38:41 +00:00
|
|
|
|
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
2017-11-09 00:30:41 +00:00
|
|
|
|
inet 127.0.0.1/8 scope host lo
|
|
|
|
|
valid_lft forever preferred_lft forever
|
2022-02-24 19:43:43 +00:00
|
|
|
|
13: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP group def
|
2018-11-16 01:38:41 +00:00
|
|
|
|
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
|
|
|
|
|
inet 172.17.0.1/16 scope global eth0
|
|
|
|
|
valid_lft forever preferred_lft forever
|
|
|
|
|
|
|
|
|
|
42sh# hostname
|
|
|
|
|
koala.zoo.paris
|
|
|
|
|
42sh# ./mydocker_exec mywebserver hostname
|
|
|
|
|
d63ceae86395
|
|
|
|
|
|
|
|
|
|
42sh# ./mydocker_exec mywebserver mount
|
|
|
|
|
42sh# ./mydocker_exec mywebserver ps aux
|
|
|
|
|
...
|
2017-11-09 00:30:41 +00:00
|
|
|
|
```
|
|
|
|
|
</div>
|
2022-04-08 20:39:14 +00:00
|
|
|
|
|
|
|
|
|
:::::
|