Docker : Le Dix-Septième pas.

1228 x served & 271 x viewed

Attention ceci est mon brouillon avant de faire une belle documentation sur Docker (il y a à boire et à manger).

Pour commencer, je vous rappelle ce très bon article sur Docker : http://www.journaldunet.com/solutions/cloud-computing/1146290-cloud-pourquoi-docker-peut-tout-changer/

  • Ces VM intègrent elles-mêmes un OS sur lequel les applications qu’elles contiennent sont exécutées. Ce n’est pas le cas du container.
  • Grâce à leur légèreté, les containers Docker sont portables de cloud en cloud
  • Les basculer d’un environnement de développement ou de test à un environnement de production peut donc se faire presque en un clic, ce qui n’est pas le cas pour la VM, plus lourde.
  • IBM notamment a réalisé un comparatif de performance entre Docker et KVM. Sa conclusion est sans appel : Docker égale ou excède les performances de cette technologie de virtualisation open source – et ce dans tous les cas testés dans le cadre du comparatif.

Maintenant je vais faire un clone de mon Docker actuel afin de faire un second Docker identique. Pour cela je fais une copie avec VirtualBox. Attention il faut avoir 21 Go de disponible sur le disque dur.

Capture d’écran 2016-05-03 à 15.52.28 Capture d’écran 2016-05-03 à 15.52.51 Capture d’écran 2016-05-03 à 15.53.00 Capture d’écran 2016-05-03 à 15.53.06

Et j’ajoute une nouvelle machine qui va utiliser cette copie.

Capture d’écran 2016-05-03 à 16.02.40 Capture d’écran 2016-05-03 à 16.03.42

Maintenant je vais lancer un serveur et voir si par défaut on peut faire appel au démon via la Remote API :

[root@localhost ~]# docker -H tcp://0.0.0.0:8000 ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
[root@localhost ~]# docker -H tcp://127.0.0.1:8000 ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
[root@localhost ~]# cat /etc/systemd/system/multi-user.target.wants/docker.service 
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/docker daemon -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

[Install]
WantedBy=multi-user.target

Je vais donc faire des modifications afin de pouvoir modifier via la Remote API.

[root@localhost ~]# cat /etc/systemd/system/multi-user.target.wants/docker.service 
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/docker daemon -H fd://
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:8000 -H unix:///var/run/docker.sock
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker.service
[root@localhost ~]# docker -H tcp://127.0.0.1:8000 ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost ~]# docker -H tcp://0.0.0.0:8000 ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Pour l’instant je n’ai rien comme conteneur car pour faire la copie j’ai du arrêter le serveur et je ne relance pas les containers après un reboot. Je vais lancer deux containers :

[root@localhost ~]# docker start postgres2
postgres2
[root@localhost ~]# docker start my-server7-1
my-server7-1

Et voici ce qui est fort (au passage on peut faire cela en SSL pour plus de sécurité, c’est même FORTEMENT recommandé ! ) c’est d’avoir une API propre et accessible via curl (requête HTTP ou HTTPS) qui permette le pilotage de notre Docker et donc d’un Docker distant. Ceci ouvre une multitudes de possibilités !

Voici le « Docker ps » en JSON :

[root@localhost ~]# curl -X GET http://localhost:8000/containers/json
[{"Id":"1f84fca3adf1b16f380cae116c03b13a30fab5fceb2895196c202d7022b93122","Names":["/my-server7-1"],"Image":"my-server7","ImageID":"sha256:2dbb7ecbdaa1510f3609d119b72db9182f005f310300fa8f581d22902a42f39a","Command":"/sbin/server8","Created":1460820049,"Ports":[{"IP":"0.0.0.0","PrivatePort":80,"PublicPort":8086,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 9 seconds","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"","EndpointID":"f1cb4c52a9bbfaf4b7f60ea27f18053c3de80050e7eb2488263ae3c217de7bc0","Gateway":"172.17.0.1","IPAddress":"172.17.0.3","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:03"}}},"Mounts":[{"Source":"/docker/app/server/1","Destination":"/app/server","Mode":"","RW":true,"Propagation":"rprivate"}]},{"Id":"2fc533c557259f65236a97e1e4eb7123867d4c0e0cae784a620cc9c96e55c168","Names":["/postgres2","/my-server6-1/postgres2","/my-server7-2/postgres2","/my-server4-1/postgres2","/my-server4.b/postgres2","/my-server4.1/postgres2","/my-server7-1/postgres2","/my-server7-4/postgres2","/my-server4-5/postgres2","/my-server4-4/postgres2","/my-server2.3/postgres2","/my-server4-2/postgres2","/my-server3.1/postgres2","/my-server4.a/postgres2","/my-server4-3/postgres2","/my-server7-3/postgres2","/my-server2.2/postgres2"],"Image":"postgres","ImageID":"sha256:0f3af79d8673d184c84d013218d43ad4eb051b71ecb4d4f7fb550c50e68c7ee7","Command":"/docker-entrypoint.sh postgres","Created":1460661691,"Ports":[{"IP":"0.0.0.0","PrivatePort":5432,"PublicPort":5432,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 11 seconds","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"","EndpointID":"6f41260f42080f869ae6278f7615fa52d86cddc094a52acbddd18f4b6799a396","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}},"Mounts":[{"Name":"f73794569bbb8d387f4a2b2562679d30b664363ab6444251c61f0c86f494ee30","Source":"/docker/volumes/f73794569bbb8d387f4a2b2562679d30b664363ab6444251c61f0c86f494ee30/_data","Destination":"/var/lib/postgresql/data","Driver":"local","Mode":"","RW":true,"Propagation":""}]}]
[root@localhost ~]# curl -X POST http://127.0.0.1:8000/containers/1f84fca3adf1b16f380cae116c03b13a30fab5fceb2895196c202d7022b93122/stop
[root@localhost ~]# curl -X GET http://localhost:8000/containers/json
[{"Id":"2fc533c557259f65236a97e1e4eb7123867d4c0e0cae784a620cc9c96e55c168","Names":["/postgres2","/my-server6-1/postgres2","/my-server7-2/postgres2","/my-server4-1/postgres2","/my-server4.b/postgres2","/my-server4.1/postgres2","/my-server7-1/postgres2","/my-server7-4/postgres2","/my-server4-5/postgres2","/my-server4-4/postgres2","/my-server2.3/postgres2","/my-server4-2/postgres2","/my-server3.1/postgres2","/my-server4.a/postgres2","/my-server4-3/postgres2","/my-server7-3/postgres2","/my-server2.2/postgres2"],"Image":"postgres","ImageID":"sha256:0f3af79d8673d184c84d013218d43ad4eb051b71ecb4d4f7fb550c50e68c7ee7","Command":"/docker-entrypoint.sh postgres","Created":1460661691,"Ports":[{"IP":"0.0.0.0","PrivatePort":5432,"PublicPort":5432,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 5 minutes","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"","EndpointID":"6f41260f42080f869ae6278f7615fa52d86cddc094a52acbddd18f4b6799a396","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}},"Mounts":[{"Name":"f73794569bbb8d387f4a2b2562679d30b664363ab6444251c61f0c86f494ee30","Source":"/docker/volumes/f73794569bbb8d387f4a2b2562679d30b664363ab6444251c61f0c86f494ee30/_data","Destination":"/var/lib/postgresql/data","Driver":"local","Mode":"","RW":true,"Propagation":""}]}]
[root@localhost ~]# curl -X POST http://127.0.0.1:8000/containers/1f84fca3adf1b16f380cae116c03b13a30fab5fceb2895196c202d7022b93122/start
[root@localhost ~]# curl -X GET http://localhost:8000/containers/json
[{"Id":"1f84fca3adf1b16f380cae116c03b13a30fab5fceb2895196c202d7022b93122","Names":["/my-server7-1"],"Image":"my-server7","ImageID":"sha256:2dbb7ecbdaa1510f3609d119b72db9182f005f310300fa8f581d22902a42f39a","Command":"/sbin/server8","Created":1460820049,"Ports":[{"IP":"0.0.0.0","PrivatePort":80,"PublicPort":8086,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 2 seconds","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"","EndpointID":"404862f963268fd44d576960077146fc5baf834ca3d72a8818ec72a6bfb3789e","Gateway":"172.17.0.1","IPAddress":"172.17.0.3","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:03"}}},"Mounts":[{"Source":"/docker/app/server/1","Destination":"/app/server","Mode":"","RW":true,"Propagation":"rprivate"}]},{"Id":"2fc533c557259f65236a97e1e4eb7123867d4c0e0cae784a620cc9c96e55c168","Names":["/postgres2","/my-server6-1/postgres2","/my-server7-2/postgres2","/my-server4-1/postgres2","/my-server4.b/postgres2","/my-server4.1/postgres2","/my-server7-1/postgres2","/my-server7-4/postgres2","/my-server4-5/postgres2","/my-server4-4/postgres2","/my-server2.3/postgres2","/my-server4-2/postgres2","/my-server3.1/postgres2","/my-server4.a/postgres2","/my-server4-3/postgres2","/my-server7-3/postgres2","/my-server2.2/postgres2"],"Image":"postgres","ImageID":"sha256:0f3af79d8673d184c84d013218d43ad4eb051b71ecb4d4f7fb550c50e68c7ee7","Command":"/docker-entrypoint.sh postgres","Created":1460661691,"Ports":[{"IP":"0.0.0.0","PrivatePort":5432,"PublicPort":5432,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 6 minutes","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"","EndpointID":"6f41260f42080f869ae6278f7615fa52d86cddc094a52acbddd18f4b6799a396","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}},"Mounts":[{"Name":"f73794569bbb8d387f4a2b2562679d30b664363ab6444251c61f0c86f494ee30","Source":"/docker/volumes/f73794569bbb8d387f4a2b2562679d30b664363ab6444251c61f0c86f494ee30/_data","Destination":"/var/lib/postgresql/data","Driver":"local","Mode":"","RW":true,"Propagation":""}]}]

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Time limit is exhausted. Please reload CAPTCHA.