User Tools

Site Tools


docker:run-stop-containers

Display running docker containers

docker ps

Output:

e26c2dcdc6a0   ee8449491514                                                                "/agentk_linux_amd64…"   41 minutes ago   Up 41 minutes                             k8s_gitlab-agent_odefta1-gitlab-agent-v2-6b8794f498-k62hm_gitlab-agent-odefta1_9f56a2c4-d4fb-4cba-9455-a84eadd25c18_5
b8a3da1af510   cbb01a7bd410                                                                "/coredns -conf /etc…"   41 minutes ago   Up 41 minutes                             k8s_coredns_coredns-76f75df574-6w59t_kube-system_28ba864d-d233-4988-a722-43cc3047da85_6
32bdc9aabb3f   43c6c10396b8                                                                "/usr/local/bin/kube…"   41 minutes ago   Up 41 minutes                             k8s_kube-proxy_kube-proxy-6mwkp_kube-system_3f8f06c3-164e-4685-bce9-17ee990f1eca_6
e319f3296383   registry.k8s.io/pause:3.9                                                   "/pause"                 41 minutes ago   Up 41 minutes                             k8s_POD_vpnkit-controller_kube-system_5060ecc9-2d01-4f2c-bd51-984045dbf482_6
42b90dc323ee   registry.k8s.io/pause:3.9                                                   "/pause"                 41 minutes ago   Up 41 minutes                             k8s_POD_coredns-76f75df574-6w59t_kube-system_28ba864d-d233-4988-a722-43cc3047da85_6

Display all docker containers

docker ps -a

Connect to an existing running container to execute commands

-it accepts container id or name

docker exec -it b1faf04f660b bash

Run a docker container

docker run --name hello-world registry.git.dovsoft.com/all/hello-world:latest

Hello World

Run a container and connect to shell

To connect to the image shell and interact (i) with terminal (t), run:

docker run -it ubuntu /bin/bash

Output:

Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
01007420e9b0: Pull complete
Digest: sha256:f9d633ff6640178c2d0525017174a688e2c1aef28f0a0130b26bd5554491f0da
Status: Downloaded newer image for ubuntu:latest
root@3a91f4539cc3:/#
If no registry is specified, the docker command will search in Docker Hub (https://registry.hub.docker.com/v2/)

Stop a running docker container

Enter the name or the ID of the container.

docker stop compassionate_galois
docker stop 3a91f4539cc3

Stop all running docker containers

For linux:

docker stop $(docker ps -q)

For windows (power shell):

docker ps -q | ForEach-Object {docker stop $_}

For windows (cmd):

FOR /f "tokens=*" %i IN ('docker ps -q') DO docker stop %i
docker/run-stop-containers.txt · Last modified: 2024/02/23 19:40 by odefta