Install and Configure the Docker on Centos

We are going to install and configure the Docker on Centos

1. Enable the epel repository.
2. yum install docker-io
3. Start the docker daemon

[root@proxy ~]# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:                                       [  OK  ]
[root@proxy ~]# chkconfig docker on

4. Download any public container images and store them in a local repository,

[root@proxy ~]# docker pull ubuntu
ubuntu:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
f3c84ac3a053: Pull complete
a1a958a24818: Pull complete
9fec74352904: Pull complete
d0955f21bf24: Pull complete
Status: Downloaded newer image for ubuntu:latest

5. To check the locally downloaded container images,

[root@proxy ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              latest              d0955f21bf24        3 weeks ago         192.7 MB

6. Start/boot a container from that image you downloaded,


[root@proxy ~]# docker run -i -t d0955f21bf24 /bin/bash
root@267515ea78a9:/#
root@267515ea78a9:/# cat /etc/issue
Ubuntu 14.04.2 LTS \n \l

7. Once you exited from container you can check the CT status,

[root@proxy ~]# docker ps  -->running CT
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@proxy ~]# docker ps -a  -->All CT's
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
267515ea78a9        ubuntu:latest       "/bin/bash"         2 minutes ago       Exited (0) 15 seconds ago                       silly_mcclintock   
[root@proxy ~]#

8. We can also start the stopped container and access it,

[root@proxy ~]# docker start 267515ea78a9
267515ea78a9
[root@proxy ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
267515ea78a9        ubuntu:latest       "/bin/bash"         4 minutes ago       Up 5 seconds                            silly_mcclintock   
[root@proxy ~]#

To access you can use "attach" command,

[root@proxy ~]# docker attach 267515ea78a9
root@267515ea78a9:/#
root@267515ea78a9:/# cat /etc/issue
Ubuntu 14.04.2 LTS \n \l

To completely remove the stopped container with using "rm" command,

[root@proxy ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
267515ea78a9        ubuntu:latest       "/bin/bash"         7 minutes ago       Exited (0) 39 seconds ago                       silly_mcclintock   
[root@proxy ~]# docker rm 267515ea78a9
267515ea78a9
[root@proxy ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

9. By default,  docker0 Linux bridge created automatically and container you create will be connected to docker0 bridge interface.

E.G,

[root@proxy ~]# docker run -i -t d0955f21bf24 /bin/bash
root@6c559dd1549f:/# ip a
4: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
5: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 scope global eth0
    inet6 fe80::42:acff:fe11:2/64 scope link
       valid_lft forever preferred_lft forever


In this container have assigned with ip address 172.17.0.2[dhcp] automatically and connected to bridge docker0.
Also you can see the bridge docker0 have ip on same subnet.

[root@proxy ~]# brctl show
bridge name    bridge id        STP enabled    interfaces
docker0        8000.eac87edcdbb9    no        vethaa856b3

[root@proxy ~]# ifconfig
docker0   Link encap:Ethernet  HWaddr EA:C8:7E:DC:DB:B9 
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::54fe:b5ff:fe83:7bee/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:624 (624.0 b)  TX bytes:1070 (1.0 KiB)

[root@proxy ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
31.x.x.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
0.0.0.0         31.x.x.1     0.0.0.0         UG    0      0        0 eth0

9. Docker uses Linux bridge to interconnect containers with each other, and to connect them to external networks.
Hence you can create a custom Linux bridge with brctl command to interconnect containers and you can assign a separate subnet to the bridge, and have Docker assigned IP addresses from the subnet to containers.[e.g. 192.168.0.0]. We can see this briefly on separate page.

10. We can also map the ports from Host to container as well as folders.
E.G. If we mapped the folder /usr/local/bin from host to container then we can use binaries exists in that /usr/local/bin folder on container.

 Note:
docker run -d -p 80:80 <ct-image> /bin/bash

Detach (-d) the container so it runs in the background (otherwise you get an interactive container -i).

Refer: https://access.redhat.com/articles/881893#getatomic

Comments

Popular posts from this blog

KVM & Qemu

PHP Fatal error: Class 'JFactory' not found

docker.errors.APIError: 400 Client Error client is newer than server