Getting Started with Docker

    0
    25
    Loading

    This is the first post on DevOps tools that I will be talking about. I will be explaining how to use automation tools to deploy scaling, contain applications, build alternatives, and perform data analytics of logs and develop enterprise cost-effective automation tools.

    Let’s begin with DOCKER.

    If you are using CentOS, follow the instructions below:

    [root@tito ~]# cd /etc/yum.repos.d
    [root@tito yum.repos.d]# vi docker.repo

    Add the below inside the newly created docker.repo.

    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/7/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg

    Next, run an update.

    [root@tito ~]# yum update

    Once updated, proceed to install the docker-engine.

    [root@tito ~]# yum install -y docker-engine

    Proceed with enabling systemctl, which will create a link to start up Docker, to start up Docker upon reboot.

    [root@tbola451 yum.repos.d]# systemctl enable docker
    Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service
    

    Now, let’s proceed to run Docker as a daemon service.

    [root@tito ~]# systemctl start docker

    YAY BINGO!!! Your Docker is running. ?

    Verify by checking your Docker version.

    [root@tbola451 ~]# docker --version
    Docker version 17.05.0-ce, build 89658be

    Your Docker is up and running. You can view your Docker images, which are empty for now because your Docker is newly installed.

    Below is what mine looks like, I don’t have any images yet ?

    [root@tbola451 ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    

    Hmmm, notice how I am using root user? That’s not cool in terms of security. Therefore, I will back out/exit root and become a regular user (the user assigned for Docker).

    [root@tbola451 ~]# exit 
    logout
    [user@tbola451 ~]$ docker images
    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.29/images/json: dial unix /var/run/docker.sock: connect: permission denied

    Oops, now you can see that you can’t connect to the Docker daemon when you tried to run the commanddocker images.

    What you need to do is become the root user again.

    Yeah, I know that I said to exit root before, but believe me, you really need to become root this time because we will be doing some file ownership modification. Sounds cool, right? ?

    [user@tbola451 ~]$ su -
    Password: 
    [root@tbola451 ~]# cd /var/run/
    [root@tbola451 run]# ls -la dock*
    [root@tbola451 run]# ls -la dock*
    -rw-r--r--. 1 root root     4 Aug 30 01:50 docker.pid
    srw-rw----. 1 root docker  0 Aug 30 01:50 docker.sock
    
    docker:
    total 0
    drwx------.  6 root root 120 Aug 30 01:50 .
    drwxr-xr-x. 28 root root 900 Aug 30 01:50 ..
    drwx------.  3 root root 100 Aug 30 01:50 libcontainerd
    drw-------.  2 root root  60 Aug 30 01:50 libnetwork
    drwx------.  2 root root  40 Aug 30 01:50 plugins
    drwx------.  2 root root  40 Aug 30 01:50 swarm

    We need to be able to connect to this sock file.srw-rw----. 1 root docker 0 Aug 30 01:50 docker.sock But, it seems like it’s owned by the root and docker group, so only root can use/connect to it (root created it, so selfish of root).

    Let’s add a user to the Docker group, my username is.user

    [root@tbola451 run]# cat /etc/group |grep docker
    docker:x:988:
    [root@tbola451 run]# usermod -a -G docker user
    [root@tbola451 run]# cat /etc/group |grep docker
    docker:x:988:user

    Nice! It seems like we fixed that pretty nicely. Exit and log in as yourUser. Mine is user and confirm. Below is my output.

    [user@tbola451 ~]$ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    [user@tbola451 ~]$ 
    [here]()

    Skipped the above? Follow the below instructions for quick Docker installation.

    [root@tbola451 ~]# cd /etc/yum.repos.d
    [root@tbola451 yum.repos.d]# vi docker.repo
    *****Add the below inside the newly created docker.repo****
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/7/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    *********************************************
    [root@tbola451 yum.repos.d]# yum update
    [root@tbola451 yum.repos.d]#yum install -y docker-engine
    [root@tbola451 yum.repos.d]# systemctl enable docker
    [root@tbola451 yum.repos.d]# systemctl start docker
    [root@tbola451 ~]# docker --version
    [root@tbola451 ~]# docker images

    YAY BINGO!!! Your Docker is running. ?


    Note: Feel free to add more to the post and correct my mistakes in the comments section. That’s all folks. ?