Karan Singh

Code Never Lies, Comments Sometime Do !!

Docker Containers in Just 10 Commands

| Comments

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
[[email protected] ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/centos    latest              fd44297e2ddb        5 weeks ago         215.7 MB
[[email protected] ~]#
  • Create Docker container
1
2
3
[[email protected] ~]# docker create -ti --name="mona" centos bash
c7f9eb6b32eba38242b9d9ced309314f8eee720dbf29c656885aa0cbfff15aa6
[[email protected] ~]#
  • Start your docker container
1
# docker start mona
  • Get IP address of your newly created docker container
1
2
3
[[email protected] ~]# docker inspect mona | grep -i ipaddress
        "IPAddress": "172.17.0.1",
[[email protected] ~]#
  • Attach (login) to your docker container
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[[email protected] ~]# docker attach mona

[[email protected] /]#
[[email protected] /]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[[email protected] /]# 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
[[email protected] /]#

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
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
c7f9eb6b32eb        centos:latest       "bash"              9 minutes ago       Up 28 seconds                           mona
[[email protected] ~]#
  • Stop and destroy container
1
2
3
4
5
6
7
[[email protected] ~]# docker stop mona ; docker kill mona
mona
mona
[[email protected] ~]#
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[[email protected] ~]#

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 !!!

Comments