Introduction à 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 peut lancer 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 :
Démarrer une application pour exécuter un enchaînement de tâches ou accepter des connexions externes.
CMD python3 my_pipeline.py
CMD postgres
Démarrer un script qui lance ensuite plusieurs applications
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Une image plus générale exige une commande de démarrage plus générale.
Démarrer une image
docker run <image>
Démarrer une image avec une commande de démarrage personnalisée
docker run <image> <shell-command>
Démarrer une image en mode interactif avec une commande de démarrage personnalisée
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Usage | Instruction Dockerfile |
|---|---|
| Ajouter une commande shell exécutée au démarrage d'un conteneur créé à partir de l'image. | CMD <shell-command> |
| Usage | Commande shell |
|---|---|
| Outrepasser la CMD définie dans l'image | docker run <image> <shell-command> |
| Outrepasser la CMD définie dans l'image et exécuter en mode interactif | docker run -it <image> <shell-command> |
Introduction à Docker