Containers

Listes des containers

sudo docker container ls -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
43ad273727ce alpine "/bin/sh" 48 seconds ago Exited (0) 46 seconds ago zen_nobel

Créer un container (exec : Foreground)

sudo docker container run <IMAGE NAME>

Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
aad63a933944: Pull complete
Digest: sha256:b276d875eeed9c7d3f1cfa7edb06b22ed22b14219a7d67c52c56612330348239
Status: Downloaded newer image for alpine:latest

Crée un container (exec : Background)

sudo docker container run -d <IMAGE NAME>

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
c499e6d256d6: Pull complete
74cda408e262: Pull complete
ffadbd415ab7: Pull complete
Digest: sha256:282530fcb7cd19f3848c7b611043f82ae4be3781cb00105a1d593d7e6286b596
Status: Downloaded newer image for nginx:latest
5d4a80ce80de32982e099c3c1ef96933787b541e817a2195a5c3f694408f30b0

Crée un container (exec : Background) avec Processus lancer dans le container

sudo docker container run -d <IMAGE NAME> ping 8.8.8.8

Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
aad63a933944: Pull complete
Digest: sha256:b276d875eeed9c7d3f1cfa7edb06b22ed22b14219a7d67c52c56612330348239
Status: Downloaded newer image for alpine:latest
092f8847039691098e3cb6f15e79b1b4d11b40da48b782af37c9fcb08ab072dd

Créer un container (Intéractif)

sudo docker container run -ti <IMAGE NAME>

Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
5bed26d33875: Pull complete
f11b29a9c730: Pull complete
930bda195c84: Pull complete
78bf9a5ad49e: Pull complete
Digest: sha256:bec5a2727be7fff3d308193cfde3491f8fba1a2ba392b7546b43a051853a341d
Status: Downloaded newer image for ubuntu:latest
[email protected]:/# <votre commande ici>

Créer un container (Mapping de port)

Port Statique : -p <HOST_PORT>:<CONTAINER_PORT>

Port Dynamique : -P <CONTAINER_PORT>

sudo docker container run -d -p 8080:80 nginx

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
c499e6d256d6: Pull complete
74cda408e262: Pull complete
ffadbd415ab7: Pull complete
Digest: sha256:282530fcb7cd19f3848c7b611043f82ae4be3781cb00105a1d593d7e6286b596
Status: Downloaded newer image for nginx:latest
984a85365b6503399bd0c6447886a39aaefcf944a6c0877edd21b7f0f6f9cab8

Stopper un container

sudo docker container stop <CONTAINER ID>

<CONTAINER ID>
43ad273727ce

Supprimer un container

sudo docker container rm <CONTAINER ID>

<CONTAINER ID>
43ad273727ce