/    /  Docker – Containers

Docker Containers

 

Containers are Docker images that can be run using the Docker run command. Docker’s basic purpose is to run containers.

Setting up a container

You run containers with Docker run. To run a container interactively, launch the Docker container first.

$ sudo docker run –itd centos /bin/bash 
  • Press Ctrl+d or exit will take you back to your OS shell.

c1

On the Ubuntu server, you will be running CentOS.

Container listing

Using the docker ps command, you can list all the containers running on the machine.

$ docker ps

Syntax

$ docker ps 

Return Value

You’ll see a list of the containers that are running right now.

Example

$ docker ps

Output

As a result of the above command:

c2

Here’s some more docker ps variations.

$ docker ps -a

Lists all the containers on the system with this command

Syntax

$ docker ps -a 

Options

  • ─a − This tells the docker ps command to list all the containers.

Return Value

All containers will be displayed in the output.

Example

$ sudo docker ps -

Output

As a result of the above command:

c3

docker history

Using this command, you can see all the commands run with an image.

Syntax

$ docker history ImageID 

Options

  • ImageID − The image ID you want to see all the commands run on.

Return Value

All commands run against that image will appear in the output.

Example

$ sudo docker history centos

It’ll show all the commands that were run against the centos  image.

Output

As a result of the above command:

c4