Spread the love


This is a step by step guide for getting started with Docker. This guide starts with a fresh CentOS 7.0 host machine, talks about how to play around with images and containers, how to start and stop the containers, how to build containers through Dockerfile and finally how to build applications with number of containers working closely and together.

I assume that a fresh CentOS 7.0 machine is installed on the bare metal machine or VM. It’s better to take a VM (either ESXi or Virtualbox) and start experimenting with the VM.My CentOS 7.0 VM looks like:-

cat /etc/os-release
NAME=”CentOS Linux”
VERSION=”7 (Core)”
ID_LIKE=”rhel fedora”
PRETTY_NAME=”CentOS Linux 7 (Core)”

Update your CentOS System using the below command:

yum update

Let us install Docker on this system:

yum install docker

To verify if Docker is properly installed or not:

docker version

The above command should display docker server and client version.

Next, we need to start docker daemon:

systemctl start docker

We haven’t pulled any images yet from Dockerhub. hence, the below command shows empty:

docker images

The command `docker info` too can help you in displaying docker information:

[root@localhost ~]# docker info
Containers: 20
Images: 0
Storage Driver: devicemapper
Pool Name: docker-253:1-18305751-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 6.264 GB
Data Space Total: 107.4 GB
Data Space Available: 3.223 GB
Metadata Space Used: 8.335 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.139 GB
Udev Sync Supported: true
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.93-RHEL7 (2015-01-28)
Execution Driver: native-0.2
Kernel Version: 3.10.0-123.20.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
CPUs: 1
Total Memory: 1.955 GiB
Name: localhost.localdomain
Username: ajeetraina
Registry: [https://index.docker.io/v1/]

How does Docker directory structure look like?

[root@localhost containers]# pwd
[root@localhost containers]# ls
[root@localhost containers]#

How to pull image from Docker Hub repository?

Let’s pull a newer Ubuntu Image as shown below:

[root@localhost ~]# docker pull ubuntu:precise
Pulling repository ubuntu
ac6b0eaa3203: Pulling image (precise) from ubuntu, endpoint: https://registry-1.ac6b0eaa3203: Download complete
c50f7e0846e6: Download complete
fd248b999044: Download complete
9f91f850df24: Download complete
Status: Downloaded newer image for ubuntu:precise

Lets verify with Docker image command to see what images it pulled:

[root@localhost ~]# docker images
ubuntu 12.04 ac6b0eaa3203 2 weeks ago 132.4 MB
ubuntu precise ac6b0eaa3203 2 weeks ago 132.4 MB
ubuntu precise-20150427 ac6b0eaa3203 2 weeks ago 132.4 MB
ubuntu 12.04.5 ac6b0eaa3203 2 weeks ago 132.4 MB
blalor/centos latest f01c1b138488 10 months ago 322.4 MB

Till now, we dont have any container yet running. It is just an image which got pulled from the remote Docker hub registry.

Lets see what does Docker info shows now:

[root@localhost ~]# docker info
Containers: 3
Images: 7
Storage Driver: devicemapper
Pool Name: docker-253:0-130986-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 3.115 GB
Data Space Total: 107.4 GB
Metadata Space Used: 2.499 MB
Metadata Space Total: 2.147 GB
Udev Sync Supported: true
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.89-RHEL6 (2014-09-01)
Execution Driver: native-0.2
Kernel Version: 2.6.32-504.16.2.el6.x86_64
Operating System: <unknown>
CPUs: 4
Total Memory: 1.833 GiB
Name: localhost.localdomain
[root@localhost ~]#

How to attach to the container?

docker attach ac6b0eaa3203
FATA[0000] Error response from daemon: No such container: ac6b0eaa3203
[root@localhost ~]#

Why the error? because the container is not in running state, we cannot attach to stopped container.

Lets start the container and provide a new name too. I would name it as collabnix.

docker run -it --name collabnix ac6b0eaa3203 /bin/bash

Please remember that if you pressed Ctrl+D to come out of the container, the container stops running. To keep container running and if you want to come out of the container, press Ctrl+P+Q. This will keep it running in the background.

Lets check it here under docker ps command.

[root@localhost ~]# docker ps
4e21f056056e ubuntu:12.04 “/bin/bash” About a minute ago Up About a minute
[root@localhost ~]#

Hence it showed that new docker container with name “collabnix” is up and running.
You can attach it to a new running container now as shown below:

[root@localhost ~]# docker attach collabnix

Running the command will take you inside the container. We can verify that we are inside the container through the following command:

Important Point: Say, I am already attached to the container and some application packages are being installed. While I try to attach again through the different terminal, the same window will get displayed. Did you remember screen command?
Yeh, it is somewhat the same.

root@4e21f056056e:/# cat /etc/os-release
VERSION=”12.04.5 LTS, Precise Pangolin”
PRETTY_NAME=”Ubuntu precise (12.04.5 LTS)”

Hence we have a running container called collabnix which we can deattach and attach to successfully and in an easy manner.

Looking inside the container

Lets see how does the container look like:

root@4e21f056056e:/# df -h
Filesystem Size Used Avail Use%
Mounted on
rootfs 9.8G 168M 9.1G 2%
/dev/mapper/docker-253:0-130986-4e21f056056ed168a5518a8db46d99099f3b436d0bc59e9e72529b6bd62109cd 9.8G 168M 9.1G 2%
tmpfs 939M 0 939M 0%
shm 64M 0 64M 0%
/dev/mapper/VolGroup-lv_root 12G 4.8G 6.0G 45%
/dev/mapper/VolGroup-lv_root 12G 4.8G 6.0G 45%
/dev/mapper/VolGroup-lv_root 12G 4.8G 6.0G 45%
tmpfs 939M 0 939M 0%

Checking the container memory:

root@4e21f056056e:/# free -m
total used free shared buffers cached
Mem: 1876 668 1208 0 14 545
-/+ buffers/cache: 108 1768
Swap: 4031 0 4031

Checking the container kernel:

root@4e21f056056e:/# uname -arn
Linux 4e21f056056e 2.6.32-504.16.2.el6.x86_64 #1 SMP Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

How to Stop and start Container?

[root@localhost ~]# docker ps
4e21f056056e ubuntu:12.04 “/bin/bash” 9 minutes ago Up 9 minutes
[root@localhost ~]# docker stop collabnix
[root@localhost ~]# docker ps
[root@localhost ~]# docker start collabnix
[root@localhost ~]# docker ps
4e21f056056e ubuntu:12.04 “/bin/bash” 12 minutes ago Up 4 seconds
[root@localhost ~]#

How to restart the container?

[root@localhost ~]# docker restart collabnix
[root@localhost ~]#

In our next post, we will discuss the advance topics on Docker containers.


Spread the love
Categories: Docker

Ajeet Raina

My name is Ajeet Singh Raina and I am an author of this blogging site. I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I bagged 2 special awards last year(2019): Firstly, “The Tip of Captain’s Hat Award” at Dockercon 2019, San Francisco, and secondly, “2019 Docker Community Award“. I run Collabnix Community Slack with over 5300+ audience . I have built popular GITHUB repositories like DockerLabs, KubeLabs, Kubetools, RedisPlanet Terraform etc. with the support of Collabnix Community. Currently working as Developer Relations Manager at Redis Labs where I help customers and community members adopt Redis. With over 12,000+ followers over LinkedIn & close to 5100+ twitter followers, I like sharing Docker and Kubernetes related content . You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)


DeetTek · 26th June 2016 at 8:20 pm

Youre so cool! I dont suppose Ive learn something like this before. So good to seek out anyone with some unique thoughts on this subject. realy thanks for starting this up. this web site is something that’s needed on the net, somebody with somewhat originality. useful job for bringing one thing new to the web! http://perfectslots2016.ru

Le Meierotto · 11th October 2016 at 1:13 am

I think that is among the most significant info for me. And i’m glad studying your article. However wanna commentary on some basic issues, The web site style is perfect, the articles is actually great : D. Excellent task, cheers|

full article · 11th October 2016 at 4:06 am

I just want to tell you that I am new to blogging and seriously loved this web-site. Probably I’m want to bookmark your website . You certainly come with superb articles. Regards for revealing your web page.

jotul · 11th October 2016 at 8:36 pm

Heya i’m for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you helped me.

Gutenberg · 27th October 2016 at 11:39 pm

There’s definately a lot to know about this subject. I like all the points you have made.|

Mica Odem · 10th November 2016 at 1:38 am

Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish just about gossips and internet and this is actually irritating. A good web site with interesting content, that’s what I need. Thank you for keeping this web site, I’ll be visiting it. Do you do newsletters? Can not find it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Hey, Wait !

Stay Informed about what's happening around DevOps community and tools.