TP - Docker - ISRC
TP - Docker - ISRC
TP : Containers Docker
1
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs
the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which
sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker Hub
account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
Un container ne reste en vie que si un processus est actif. On peut lister les containers
actifsavec la commande docker ps. On peut aussi lister tous les containers, actifs ou
inactifs avec docker ps -a.
2
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
root@osboxes:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
root@osboxes:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
48564eb0d27c ubuntu "/bin/bash" 21 seconds
ago Exited (0) 20 seconds ago clever_minsky
cb96c775cc8d hello-world "/hello" 9 minutes ago
Exited (0) 9 minutes ago naughty_allen
Nous allons maintenant rediriger l'entrée standard du container avec l'option -i et ouvrir
un pseudo-terminal avec -t, le tout en exécutant le processus /bin/bash
root@osboxes:~# docker run -ti --name=ubuntu ubuntu /bin/bash
root@7bd8427382bb:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@7bd8427382bb:/# exit
On peut inspecter ce qui se passe dans le container depuis la machine hôte avec la
commande, essayer sur un autre terminal de taper :
root@osboxes:~# docker stats toto (sur un autre terminal)
root@osboxes:~# docker logs -f toto (sur un autre terminal)
root@osboxes:~# docker stats toto (sur un autre terminal)
3
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
Nous allons maintenant créer notre propre image qui va nous permettre de lancer un
serveur Web apache. Pour cela, il faut définir la méthode de construction du container
dans un fichier.
root@osboxes:~# mkdir -p Docker/Apache
root@osboxes:~# cd Docker/Apache
root@osboxes:~# nano Dockerfile
FROM debian:latest
MAINTAINER GRASSA
RUN apt-get -yqq update && apt-get install -yqq apache2
WORKDIR /var/www/html
ENTRYPOINT [ "/usr/sbin/apache2" ]
CMD ["-D", "FOREGROUND"]
EXPOSE 80
4
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
Nous allons corriger le problème précédent en faisant quelque chose dans le container
root@osboxes:~# docker run –d –name=demon debian sh -c 'while true;do
echo "hello Nordine";sleep 1;done'
root@osboxes:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
94f61cf9c0ba debian "sh -c 'while true;do" 7
seconds ago Up 6 seconds zen_yalow
5
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
On peut mieux contrôler le port choisi. Si par exemple on veut que cela soit le port 80,
il suffit de modifier la commande précédente :
root@osboxes:~# docker rm apache
root@osboxes:~# docker run -d -p 80:80 --name=apache grassa/apache
077f87115365cd3aee583bcc0d665b587cce418724d4f13bd6a9e5ad622b0b37
root@osboxes:~# docker port apache 80
0.0.0.0:80
6
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
On veut maintenant en plus contrôler le contenu du serveur Web depuis l'hôte. Pour
cela on va :
(a) créer un répertoire website dans le répertoire Apache crée précédemment.
(b) mettre dans ce répertoire un fichier index.html avec le contenu suivant :
root@osboxes:~/Docker/Apache# mkdir website
root@osboxes:~/Docker/Apache# cd website/
root@osboxes:~/Docker/Apache/website# ls
root@osboxes:~/Docker/Apache/website# nano index.html
<html>
cela fonctionne
</html>
root@osboxes:~# docker rm -f apache
apache
7
TP DOCKER ISRC-FC_USMS Pr Driss AIT OMAR
REFERENCE:
https://docs.docker.com/engine/installation/linux/debian/
https://mondedie.fr/d/7164-Tuto-Utilisation-de-Docker/7