How to stop and start a docker container


Example - Docker Stop and Start containers

Let us take a look at how to stop and start a docker container,

First let's create a container using the docker run command,

% docker run -id --name my_alpine alpine
a7fdf87c9868281057018c20cbfcaa0c8108214b4f2a151ff9f22d8627774c38

Let's see the details of the running docker containers using the docker ps command,

% docker ps
CONTAINER ID   IMAGE     COMMAND     CREATED          STATUS          PORTS     NAMES
a7fdf87c9868   alpine    "/bin/sh"   53 seconds ago   Up 52 seconds             my_alpine

Stop a docker Container

To stop a docker container make use of the command docker stop followed by the CONTAINER ID or the name of the docker container,

Example:
% docker stop my_alpine
my_alpine

Let's see if got stopped with the docker ps command again, but this time with a -a option,

% docker ps -a
CONTAINER ID   IMAGE     COMMAND     CREATED          STATUS                        PORTS     NAMES
a7fdf87c9868   alpine    "/bin/sh"   24 minutes ago   Exited (137) 1 minutes ago             my_alpine


Start a Start a stopped Docker Container

As you may have guessed we can start a stopped/exited container using docker start <container_name or id>

% docker start a7fdf87c9868
a7fdf87c9868
% docker ps
CONTAINER ID   IMAGE     COMMAND     CREATED          STATUS         PORTS     NAMES
a7fdf87c9868   alpine    "/bin/sh"   28 minutes ago   Up 2 minutes             my_alpine
-


Have Questions? Post them here!

Top Hashtags:

Advertisements

Advertisements




Advertisements