How to Stop a Docker Container

Posted on

Introduction

This is an article which is showing how to stop a docker container. Actually, in order to stop a docker container is very easy. Just perform the suitable command to do it. So, there is already an existing docker container which is running. The aim is to show how to stop that running docker container.

How to Stop a Docker Container

In order to stop a running docker container, the following are the steps to do it :

  1. First of all, just list the available container by typing the following command :

    C:\mydocker-build>docker container list --all
    CONTAINER ID IMAGE COMMAND                            CREATED     STATUS                       PORTS                     NAMES
    080db122cd99 registry "/entrypoint.sh /etc…"          3 weeks ago Up 13 hours                  0.0.0.0:5000->5000/tcp hub.local
    9287843d4bce docker101tutorial "/docker-entrypoint.…" 3 weeks ago Exited (255) 3 weeks ago     0.0.0.0:80->80/tcp     docker-tutorial
    302c0da3bc61 alpine/git "git clone https://g…"        4 weeks ago Exited (0) 4 weeks ago                                 repo
    C:\mydocker-build>
    
  2. Next, just list all the available image by typing the following command :

    C:\mydocker-build>docker image list --all
    REPOSITORY                         TAG    IMAGE ID     CREATED      SIZE
    mydockerapp                        latest e1d4421cfe4b 22 hours ago 1.04GB
    docker101tutorial                  latest 7f8109362ad3 3 weeks ago  28.5MB
    hub.docker.local:5000/local-alpine latest c059bfaa849c 5 weeks ago  5.59MB
    alpine/git                         latest c6b70534b534 6 weeks ago  27.4MB
    registry                           latest b8604a3fe854 7 weeks ago  26.2MB
    ubuntu                             latest ba6acccedd29 2 months ago 72.8MB
    centos                             latest 5d0da3dc9764 3 months ago 231MB
    hello-world                        latest 22773018c042 3 months ago 231MB
    hub.docker.local:5000/hello-world  latest 22773018c042 3 months ago 231MB
    C:\mydocker-build>
  3. Before stopping the docker container, just choose to run one of the docker image available for the simulation to stop the docker container.

    C:\mydocker-build>docker run -it -d hello-world /bin/bash
    90a98911207b1c63fc611097bad9e794135138f0c841361f28e56e9d66791b18
    C:\mydocker-build>docker container list --all
    CONTAINER ID IMAGE COMMAND                            CREATED        STATUS                   PORTS                     NAMES
    90a98911207b hello-world "/bin/bash"                  10 seconds ago Up 7 seconds                                       wizardly_mirzakhani
    080db122cd99 registry "/entrypoint.sh /etc…"          3 weeks ago    Up 13 hours              0.0.0.0:5000->5000/tcp hub.local
    9287843d4bce docker101tutorial "/docker-entrypoint.…" 3 weeks ago    Exited (255) 3 weeks ago 0.0.0.0:80->80/tcp     docker-tutorial
    302c0da3bc61 alpine/git "git clone https://g…"        4 weeks ago    Exited (0) 4 weeks ago                             repo
    C:\mydocker-build>
    
  4. Finally, in this case, stopping the docker container is possible for further demonstration using the docker container with the id of ’90a98911207b’. Just type the following command :

    C:\mydocker-build>docker stop 90a98911207b
    90a98911207b
    C:\mydocker-build>
    

    Check again by listing all of the containers by typing the following command :

    C:\mydocker-build>docker container list --all
    CONTAINER ID IMAGE COMMAND                            CREATED        STATUS                   PORTS                     NAMES
    90a98911207b hello-world "/bin/bash"                  27 seconds ago Exited (0) 3 seconds ago                           wizardly_mirzakhani
    080db122cd99 registry "/entrypoint.sh /etc…"          3 weeks ago    Up 13 hours              0.0.0.0:5000->5000/tcp hub.local
    9287843d4bce docker101tutorial "/docker-entrypoint.…" 3 weeks ago    Exited (255) 3 weeks ago 0.0.0.0:80->80/tcp     docker-tutorial
    302c0da3bc61 alpine/git "git clone https://g…"        4 weeks ago    Exited (0) 4 weeks ago                             repo
    C:\mydocker-build>
    

    As in the above output command execution, the docker container with the id of ’90a98911207b’ has finally stop.

One thought on “How to Stop a Docker Container

Leave a Reply