Docker Commands

Docker is an open source project that was released by dotCloud in 2013. Docker is build on features of Linux Container (LXC) technology, and just like any container technology it has its own file system, storage, CPU, RAM memory, etc.

But hey, what is a container? From the very basic point of view, a container encapsulates all the software dependencies associated with a running application. There are two core concepts of the containers:

  1. Package together application and all its dependencies as a single deployable unit. This results in faster innovation and quicker deployment cycles. It also reduces regression risk due to the OS upgrades;
  2. Decouples the application from the operating system, which allows containers to be portable for resiliency and scalability.

Docker Components:

  • Image
  • Container (a container is the standard unit in which the application service resides or is transported).
  • Docker hub/registry
  • Docker engine
  • Docket file

To start working with docker first thing you should do is to install docker engine (known also as docker hub). If you are running MAC OS you should install it from here. Now that you have docker installed, let’s see some docker command in action.

Docker images vs. docker containers

Before going further I consider it is necessary to clarify difference between docker images and docker container. Although they are related and often confused, they are not the same concept.

Docker images are a frozen copy of the system at some given point, while a docker container is an image when docker runs. I you want make a comparison with Java programming language, think at docker images are like classes while docker containers are like instances.

Check your docker version

You can use docker –version or docker -v to get the docker version which you are running.

Additionally, you have the option to run docker version command which gives you more insights for both docker client and docker server. Docker server refers to the docker daemon.

With docker info you can display system information about docker.

Check how many containers are running

To find out how many containers are running you can always run the docker ps command.

You can use docker ps -a and it will show you all the container (indiferent daca sunt oprite, started sau in orice alta status).

This command will show you a list of all the running processes.

Get statistics about the running containers

docker stats

Get the list of all the available images

docker images

This command shows a list of the docker images cached locally (aka, images available in your local box). An image is specified by the repository name and tag (repository:tag).

Search for docker images

docker search <key-word>

This command will search for images in the docker hub repository.

Build a docker image from a DockerFile

docker build

Run a docker container in the background

docker run -d <container-name>

The docker run command will create the container using the specified image (it will be downloaded from docker hub if not available locally). The -d flag is used to run the container in the background.

Other flags available:

-i starts an interactive container. When finish you can type exit, to exit the container (docker also will shout down the container).
-t creates a pseudo-TTY that attaches stdin and stdout.

-P specify the port details

With docker run -it <container-name> /bin/bash you can enter into the container and run commands inside the container.

Remove a container

You can always remove a container if you know its id

docker rm <container-id>

Open an interactive bash shell inside the one of the running containers

docker <container-name> /bin/bash

docker exec <container-name>

Stop a container

docker stop <container-id>

And if you can’t remember any of the above commands you can type

docker –help

docker –help | grep -i image

Other alternatives to Docker:

  • rocket containers
  • garden cloud foundry
  • open container initiative

Useful Resources:

An introduction to containers

Spread the love

Leave a Reply