A Walk Through Some Important Docker Commands

April 10, 2015 | By in LINUX HOWTO
| 1 Reply More

Hi everyone today we'll learn some important Docker Commands that you'll need to learn before you go with Docker. Docker is an Open Source project that provides an open platform to pack, ship and run any application as a lightweight container. It has no boundaries of Language support, Frameworks or packaging system and can be run anywhere, anytime from a small home computers to high-end servers. It makes them great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider.

Docker commands are easy to learn and easy to implement or take into practice. Here are some easy Docker commands you'll need to know to run Docker and fully utilize it.

1. Pulling a Docker Image

First of all, we'll need to pull a docker image to get started cause containers are built using Docker Images. We can get the required docker image from the Docker Registry Hub. Before we pull any image using pull command, we'll need to protect our system as there is identified a malicious issue with pull command. To protect our system from this issue, we'll need to add index.docker.io into /etc/hosts entry. We can do using our favorite text editor.

# nano /etc/hosts

Now, add the following lines into it and then save and exit. index.docker.io

Docker Hosts

To pull a docker image, we'll need to run the following command.

# docker pull registry.hub.docker.com/busybox

Docker pull command

We can check whether any Docker image is available in our local host for the use or not.

# docker images

Docker Images

2. Running a Docker Container

Now, after we have successfully pulled a required or desired Docker image. We'll surely want to run that Docker image. We can run a docker container out of the image using docker run command. We have several options and flags to run a docker container on the top of the Docker image. To run a docker image and to get into the container we'll use -t and -i flag as shown below.

# docker run -it busybox

Docker Run Shell Command

From the above command, we'll get entered into the container and can access its content via the interactive shell. We can press Ctrl-D in order to exit from the shell access.

Now, to run the container in background, we'll detach the shell using -d flag as shown below.

# docker run -itd busybox

Run Container Background

If we want to attach into a running container, we can use attach command with the container id. The container id can be fetched using the command docker ps .

# docker attach <container id>

Docker Attach

3. Checking Containers

It is very easy to check the log whether the container is running or not. We can use the following command to check whether there is any docker container running in the real time or not using the following command.

# docker ps

Now, to check logs about the running or past running containers we'll need to run the following command.

# docker ps -a

View Docker Containers

 4. Inspecting a Docker Container

We can check every information about a Docker Container using the inspect command.

# docker inspect <container id>

Docker Inspect

5. Killing and Deleting Command

We can kill or stop process or docker containers using its docker id as shown below.

# docker stop <container id>

To stop every containers running, we'll need to run the following command.

# docker kill $(docker ps -q)

Now, if we wanna remove a docker image, run the below command.

# docker rm <container id>

If we wanna remove all the docker images at once, we can run the below.

# docker rm $(docker ps -aq)


These docker commands are highly essential to learn to fully utilize and use Docker. Docker gets too simple with these commands providing end users an easy platform for computing. It is extremely easy for anyone to learn about Docker commands with this above tutorial. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve and update our contents. Thank you ! Enjoy :-)


Share This :

Free Linux Ebook to Download

Comments (1)

Trackback URL | Comments RSS Feed

  1. AndresVia says:

    Is adding the host entre still neccesary? What is the security problem with pull. I find editing my hosts file, inconvenient.

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.