Docker Container - Start and Stop

Docker container is a running instance of an image. In this guide, we will see the useful commands related to containers.

docker container stop

This command stops one or more running containers. Syntax

docker container stop [OPTIONS] CONTAINER [CONTAINER...]

Options

--time , -t: Seconds to wait for a stop before killing it. Its default value is 10sec.

Example

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                        NAMES
ad9f71ce3a04   ubuntu:14.04   "/bin/bash"              9 minutes ago   Up 9 minutes                           unruffled_newton
learning-ocean:~ gaurav$ docker container stop ad
ad
learning-ocean:~ gaurav$

docker container start

This command starts one or more stopped containers.

Syntax

$docker container start [OPTIONS] CONTAINER [CONTAINER...]

Options

--attach -a: Attach STDOUT/STDERR and forward signals
--detach-keys: Override the key sequence for detaching a container
--interactive , -i: Attach container's STDIN

Example

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED       STATUS      PORTS                              NAMES

learning-ocean:~ gaurav$ # no container is running in my machine.

learning-ocean:~ gaurav$ # lets list all the container (stopped as well as running)

learning-ocean:~ gaurav$ docker container ls -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS         PORTS                    NAMES
ad9f71ce3a04   ubuntu:14.04          "/bin/bash"              13 minutes ago   Exited (0) About a minute ago    unruffled_newton

learning-ocean:~ gaurav$ #lets start ubuntu container
learning-ocean:~ gaurav$ docker container start ad
ad

learning-ocean:~ gaurav$ #list running container again
learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                  NAMES
ad9f71ce3a04   ubuntu:14.04   "/bin/bash"              14 minutes ago   Up 16 seconds                        unruffled_newton
learning-ocean:~ gaurav$