Docker Containers in Just 10 Commands

syndicated

Docker container in 10 commands

If you are on this page, then you definately know what is Docker , i will not take your time with the introduction part.

Lets do Docker !!!

  • Install docker packages on your Linux host , in my case its CentOS.
1
# yum install -y docker-io
  • Start Docker service and enable it as a startup process.
1
# service docker start ; chkconfig docker on
  • Docker pull CentOS image
1
# docker pull centos:latest
  • Check docker images
1
2
3
4
[root@karan-ws ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/centos    latest              fd44297e2ddb        5 weeks ago         215.7 MB
[root@karan-ws ~]#
  • Create Docker container
1
2
3
[root@karan-ws ~]# docker create -ti --name="mona" centos bash
c7f9eb6b32eba38242b9d9ced309314f8eee720dbf29c656885aa0cbfff15aa6
[root@karan-ws ~]#
  • Start your docker container
1
# docker start mona
  • Get IP address of your newly created docker container
1
2
3
[root@karan-ws ~]# docker inspect mona | grep -i ipaddress
        "IPAddress": "172.17.0.1",
[root@karan-ws ~]#
  • Attach (login) to your docker container
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@karan-ws ~]# docker attach mona

[root@c7f9eb6b32eb /]#
[root@c7f9eb6b32eb /]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@c7f9eb6b32eb /]# df -h
Filesystem                                                                                          Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-16852579-c7f9eb6b32eba38242b9d9ced309314f8eee720dbf29c656885aa0cbfff15aa6  9.8G  268M  9.0G   3% /
tmpfs                                                                                               1.6G     0  1.6G   0% /dev
shm                                                                                                  64M     0   64M   0% /dev/shm
tmpfs                                                                                               1.6G     0  1.6G   0% /run
tmpfs                                                                                               1.6G     0  1.6G   0% /tmp
/dev/vda1                                                                                            10G  1.6G  8.5G  16% /etc/hosts
tmpfs                                                                                               1.6G     0  1.6G   0% /run/secrets
tmpfs                                                                                               1.6G     0  1.6G   0% /proc/kcore
[root@c7f9eb6b32eb /]#

To detach from docker container use ctrl+p+q , avoid using exit command as it will stop container and exit.

  • List container
1
2
3
4
[root@karan-ws ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
c7f9eb6b32eb        centos:latest       "bash"              9 minutes ago       Up 28 seconds                           mona
[root@karan-ws ~]#
  • Stop and destroy container
1
2
3
4
5
6
7
[root@karan-ws ~]# docker stop mona ; docker kill mona
mona
mona
[root@karan-ws ~]#
[root@karan-ws ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@karan-ws ~]#

These are elementary basic docker operations that you can perform to take a feel of Docker Container technology. In future posts i will cover more advance docker topics. Stay Tuned !!!