Présentation de Docker
Tim Sangster
Software Engineer @ DataCamp
L'image hello-world affiche du texte puis s'arrête.
docker run hello-world
Hello from Docker!
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon created a new container from the hello-world image which runs the
executable that produces the output you are currently reading.
3. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
Une image avec Python pourrait démarrer Python au démarrage.
docker run python3-sandbox
Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
...
....
>>> exit()
repl@host:/#
CMD <shell-command>
L'instruction CMD :
Lancement d'une application pour exécuter un flux de travail ou accepter des connexions externes.
CMD python3 my_pipeline.py
CMD postgres
Lancement d’un script qui, à son tour, lance plusieurs applications
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Une image plus générale nécessite une commande de démarrage plus générale.
Démarrage d'une image
docker run <image>
Démarrage d’une image avec une commande de démarrage personnalisée
docker run <image> <shell-command>
Démarrage interactif d'une image à l'aide d'une commande de démarrage personnalisée
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Utilisation | Instruction Dockerfile |
|---|---|
| Ajoutez une commande shell à exécuter lors du démarrage d'un conteneur à partir de l'image. | CMD <shell-command> |
| Utilisation | Commande shell |
|---|---|
| Remplacer le CMD défini dans l'image | docker run <image> <shell-command> |
| Remplacer la commande définie dans l'image et exécuter de manière interactive | docker run -it <image> <shell-command> |
Présentation de Docker