Tuesday, January 27, 2015

Step by step to set up Docker on Centos 7

Playing with Docker and its fun !!!

1. Update your system up to the current patch level
# yum -y update

2. Install ducker package.
# yum -y install docker docker-registry

3. Start Docker and enable it to run upon reboot
# systemctl enable docker.service
ln -s '/usr/lib/systemd/system/docker.service' '/etc/systemd/system/multi-user.target.wants/docker.service'

# systemctl start docker.service

4. Verify that the docket service is starting
# systemctl status docker.service
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled)
   Active: active (running) since Tue 2015-01-27 21:59:53 EST; 37s ago
     Docs: http://docs.docker.com

Note: you can add local user to use docket.

# id jay
uid=1001(jay) gid=1001(jay) groups=1001(jay)
# getent group docker
docker:x:990:

# usermod -aG docker jay
# id jay
uid=1001(jay) gid=1001(jay) groups=1001(jay),990(docker)

5. Download the docker container from Docker Index
# docker pull centos
Pulling repository centos
8efe422e6104: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
Status: Downloaded newer image for centos:latest

6. Verify that the images have been fetched locally.
# docker images centos
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos7             8efe422e6104        3 weeks ago         224 MB
centos              latest              8efe422e6104        3 weeks ago         224 MB
centos              7                   8efe422e6104        3 weeks ago         224 MB

7. Run a basic cat command using the docker.
# docker run centos:centos7 cat /etc/centos-release
CentOS Linux release 7.0.1406 (Core)

8. Run the docker container
[root@localhost ~]# docker run -i -t centos /bin/bash
Note: -i attaches stdin and stdout, -t allocates a tty
[root@b01e2e6f2688 /]# pwd
/
[root@b01e2e6f2688 /]# ls
bin  etc   lib    lost+found  mnt  proc  run   selinux  sys  usr
dev  home  lib64  media       opt  root  sbin  srv      tmp  var
[root@b01e2e6f2688 /]# pwd
/
[root@b01e2e6f2688 /]# cat >/test.file
This is created under docker centos
[root@b01e2e6f2688 /]#

To get out off the container ( To disconnect, or detach, from the shell )
use escape sequence Ctrl-p + Ctrl-q.

[root@b01e2e6f2688 /]#
type ctrl +p and ctrl q to exit out off the docker. or you can use the exit command

[root@localhost ~]# cat /test.file
cat: /test.file: No such file or directory
[root@localhost ~]#

9. To search the docker available, use the docker search command.

[root@localhost ~]# docker search centos
NAME                                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                  The official build of CentOS.                   768       [OK]


[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES
b01e2e6f2688        centos:7            "/bin/bash"            7 minutes ago       Up 7 minutes                                   sad_elion
a7ce8ce380b8        centos:7            "cat /etc/centos-rel   9 minutes ago       Exited (0) 9 minutes ago                       clever_brattain


Attach a docker container

[root@localhost ~]# docker attach b01e2e6f2688

[root@b01e2e6f2688 /]#

Install git on the server
[root@b01e2e6f2688 /]# yum install git

Complete!
[root@b01e2e6f2688 /]# git --version
git version 1.8.3.1

[root@b01e2e6f2688 /]# git config --global user.name "jay"
[root@b01e2e6f2688 /]# git config --global user.email "jay@sama.expanor.local"
[root@b01e2e6f2688 /]#

[root@b01e2e6f2688 /]# cd /opt
[root@b01e2e6f2688 opt]# cd
[root@b01e2e6f2688 ~]# cat .gitconfig
[user]
        name = jay
        email = jay@sama.expanor.local
[root@b01e2e6f2688 ~]#

or
[root@b01e2e6f2688 ~]# git config --list
user.name=jay
user.email=jay@sama.expanor.local

Disconnect, or detach, from the Docker shell

CTRL+p; CTRL+q

Commit changes to Docker

[root@localhost ~]# docker commit b01e2e6f2688 my-centos-with-git
2dd94bb41bf4b96d569aed1cc5f353282e7c40bbea3948146c841c4dddeb2df7


Check the logs on the dockers
[root@localhost ~]# docker logs b01e2e6f2688  | more

Search other available dockers.
[root@localhost ~]# docker search ubuntu

[root@localhost ~]# docker pull ubuntu
Pulling repository ubuntu
b39b81afc8ca: Download complete
511136ea3c5a: Download complete
53f858aaaf03: Download complete
837339b91538: Download complete
615c102e2290: Download complete
Status: Downloaded newer image for ubuntu:latest
[root@localhost ~]#

root@localhost ~]# docker pull fedora
Pulling repository fedora
834629358fe2: Download complete
511136ea3c5a: Download complete
00a0c78eeb6d: Download complete
Status: Downloaded newer image for fedora:latest
[root@localhost ~]#


[root@localhost ~]# docker images fedora
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
fedora              21                  834629358fe2        3 weeks ago         250.2 MB
fedora              latest              834629358fe2        3 weeks ago         250.2 MB
[root@localhost ~]#


[root@localhost ~]# docker images ubuntu
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              14.04               b39b81afc8ca        11 days ago         192.7 MB
ubuntu              14.04.1             b39b81afc8ca        11 days ago         192.7 MB
ubuntu              latest              b39b81afc8ca        11 days ago         192.7 MB
ubuntu              trusty              b39b81afc8ca        11 days ago         192.7 MB
[root@localhost ~]#


Login to UbuntU docker.

[root@localhost ~]# docker run -i -t ubuntu /bin/bash
root@0303170b0c59:/# pwd
/
root@0303170b0c59:/# cat >/test.me
This is docker UbuntU
root@0303170b0c59:/# df -h .
Filesystem                                                                                         Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:1-3149016-0303170b0c59d20c65b4babfc755be19bb42809a932fd848790cfacfbde1590c  9.8G  245M  9.0G   3% /
root@0303170b0c59:/#

[root@localhost ~]# cat /test.me
cat: /test.me: No such file or directory
[root@localhost ~]#


[root@localhost ~]# su - jay
[jay@localhost ~]$ docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS               NAMES
0303170b0c59        ubuntu:14.04        "/bin/bash"         2 minutes ago       Exited (0) About a minute ago                       stoic_wozniak
[jay@localhost ~]$


No comments:

Post a Comment