How to Use the Docker Commands To List, Start, Run and Stop Your Docker Containers

Published on Aug. 22, 2023, 12:13 p.m.

Docker replicates a specific operating environment on top of a host OS.Each environment is a “Container”.Managing containers is essential for working in containers.

The basic format for using docker is the following:

docker command [options]

List Docker Containers .

To list all running Docker containers:

docker ps

To list all containers, both running and stopped by .

docker ps –a

To list containers by their ID use –aq (quiet):

docker ps –aq

To list the entire file size of each containers, use –s (size):

docker ps –s

To list the latest created containers.

docker ps –l

Start Docker Container

The main command to launch or start is docker start:

docker start [options] container_id 

You can specify the container by either using its name or ID.

To create a new container from an image and start it.

docker run [options] image [command] [argument] 

To define theContainer name , use the -name option :

docker run ––name=Ubuntu_Test ubuntu:14.04

To start the containers in interactive mode, use the options -i and -t :

docker run –it ––name=Ubuntu_Test ubuntu:14.04

Instead of using -i or -t options, use the attach command.

docker attach container_id

Stop Docker Container

Use the docker stop command to stop.

docker stop [option] container_id

To stop all running containers.

docker stop $(docker ps –a –q)