User Tools

Site Tools


docker:run-stop-containers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
docker:run-stop-containers [2024/02/19 23:20] – removed - external edit (Unknown date) 127.0.0.1docker:run-stop-containers [2024/02/23 19:39] odefta
Line 1: Line 1:
 +===== Display running docker containers =====
 +
 +<code>
 +docker ps
 +</code>
 +Output:
 +<code>
 +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
 +</code>
 +
 +===== Display all docker containers =====
 +
 +<code>
 +docker ps -a
 +</code>
 +
 +====== Connect to an existing running container to execute commands ======
 +
 +-it accepts container id or name
 +<code>
 +docker exec -it b1faf04f660b bash
 +</code>
 +
 +====== Run a docker container ======
 +
 +<code>
 +docker run --name hello-world registry.git.dovsoft.com/all/hello-world:latest
 +</code>
 +Hello World
 +
 +===== Run a container and connect to shell =====
 +
 +To connect to the image shell and interact (i) with terminal (t), run:
 +<code>
 +docker run -it ubuntu /bin/bash
 +</code>
 +Output:
 +<code>
 +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:/#
 +</code>
 +
 +<note>
 +If no registry is specified, the docker command will search in Docker Hub (https://registry.hub.docker.com/v2/)
 +</note>
 +
 +====== Stop a running docker container ======
 +
 +Enter the name or the ID of the container.
 +<code>
 +docker stop compassionate_galois
 +</code>
 +
 +<code>
 +docker stop 3a91f4539cc3
 +</code>
 +
 +===== Stop all running docker containers =====
 +
 +For linux:
 +<code>
 +docker stop $(docker ps -q)
 +</code>
 +
 +For windows (power shell):
 +<code>
 +docker ps -q | ForEach-Object {docker stop $_}
 +</code>
 +
 +For windows (cmd):
 +<code>
 +FOR /f "tokens=*" %i IN ('docker ps -q') DO docker stop %i
 +</code>
  
docker/run-stop-containers.txt · Last modified: 2024/02/23 19:40 by odefta