DOCKER CONTAINER EXEC
Commande : docker container exec
Usage: docker container exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container Options: -d, --detach Detached mode: run command in the background --detach-keys string Override the key sequence for detaching a container -e, --env list Set environment variables -i, --interactive Keep STDIN open even if not attached --privileged Give extended privileges to the command -t, --tty Allocate a pseudo-TTY -u, --user string Username or UID (format:[: ]) -w, --workdir string Working directory inside the container
Exécuter une commande sur un container en cours d’exécution :
docker container exec [options] container command [arg...]
Equivaut à :
docker exec [options] container command [arg...]
ex :
Exécuter un ping en foreground sur le container nommé test :
$ docker container exec test /bin/bash -c 'ping -c 3 8.8.8.8'
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=19.6 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=18.2 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=24.1 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 18.204/20.662/24.160/2.542 ms
Exécuter un ping en background sur le container nommé test :
$ docker container exec -d test /bin/bash -c 'ping -c 3 8.8.8.8' $
Exécuter un bash en attachant le container nommé test :
$ docker container exec -it test /bin/bash root@863dc06b964a:/#