Saturday 4 June 2022

 Create a Yum Local repository

# yum install createrepo yum-utils epel-release nginx

# systemctl enable nginx

# systemctl start nginx

# systemctl status nginx

# firewall-cmd --zone=public --permanent --add-service=http

# firewall-cmd --reload

# mkdir -p /var/www/html/repos/{base,centosplus,extra,updates}

# reposync -g -l -d -m --repoid=base --newest-only --downloadcomps --download-metadata --download_path=/var/www/html/repos/

# reposync -g -l -d -m --repoid=centosplus --newest-only --downloadcomps --download-metadata --download_path=/var/www/html/repos/

# reposync -g -l -d -m --repoid=extras --newest-only --downloadcomps --download-metadata --download_path=/var/www/html/repos/

# reposync -g -l -d -m --repoid=updates --newest-only --downloadcomps --download-metadata --download_path=/var/www/html/repos/

# createrepo -v /var/www/html/repos/base/ -g comps.xml 

# createrepo -v /var/www/html/repos/centosplus/ -g comps.xml

# createrepo -v /var/www/html/repos/extras/ -g comps.xml

# createrepo -v /var/www/html/repos/updates/ -g comps.xml


Options error: --dh fails with 'dh2048.pem': No such file or directory (errno=2)

Options error: --cert fails with 'server.crt': No such file or directory (errno=2)

Options error: Please correct these errors.


-g – enables removing of packages that fail GPG signature checking after downloading.

-l – enables yum plugin support.

-d – enables deleting of local packages no longer present in the repository.

-m – enables downloading of comps.xml files.

--repoid – specifies the repository ID.

--newest-only – tell reposync to only pull the latest version of each package in the repos.

--download-metadata – enables downloading all the non-default metadata.

--download_path – specifies the path to download packages.


# vi /etc/nginx/conf.d/repos.conf

server {

        listen   80;

        server_name  192.168.10.1;  

        root   /var/www/html/repos;

        location / {

                index  index.php index.html index.htm;

                autoindex on;

        }

}


# systemctl restart nginx


Daily Update repository server

# vi /etc/cron.daily/update-localrepos

#!/bin/bash

##specify all local repositories in a single variable

LOCAL_REPOS=”base centosplus extras updates”

##a loop to update repos one at a time 

for REPO in ${LOCAL_REPOS}; do

reposync -g -l -d -m --repoid=$REPO --newest-only --download-metadata --download_path=/var/www/html/repos/

createrepo -g comps.xml /var/www/html/repos/$REPO/  

done

# chmod 755 /etc/cron.daily/update-localrepos


Client config


# vi /etc/yum.repos.d/local-repos.repo

[local-repo]

name=Local CentOS Repository

baseurl=http://192.168.10.1/base

gpgcheck=0

enabled=1


# yum repolist

# yum search nano

# yum install nano



 What is Docker

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.


IMAGES

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization.


CONTAINERS

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.


Install Docker Centos


# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo 

# yum sudo makecache

# yum install docker-ce --nobest

# systemctl enable docker

# systemctl status docker

# systemctl start docker

# docker run hello-world

# docker (list all command options)

# docker search browser (search for an image)

# docker pull centos (this will download an image to your local Docker repository)

# docker images (this will show all images stored onto your Docker repository)

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE

centos        latest    300e315adb2f   5 days ago      209MB

hello-world   latest    bf756fb1ae65   11 months ago   13.3kB

#  docker run centos cat /etc/hosts (To run a command inside the centos container and exit)


# docker ps -l (This will list containers)

CONTAINER ID   IMAGE     COMMAND            CREATED              STATUS                          PORTS     NAMES

cf8ddd1911bb   centos    "cat /etc/hosts"   About a minute ago   Exited (0) About a minute ago             fervent_bose


# docker start cf8ddd1911bb (Re-run the same container using existing container ID)

# docker stop cf8ddd1911bb (this container is alread in exit state, but if you want to stop a running container use the command 'STOP')

# docker images (this command shows all images stored on your Docker repository)

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE

centos        latest    300e315adb2f   5 days ago      209MB

hello-world   latest    bf756fb1ae65   11 months ago   13.3kB


Interactive SHELL within a container

# docker run -it centos bash (this command will start the container and initiate a BASH SHELL where you can interact with the container)

#exit and it will stop the container


# Keep container running and exit to host

<Ctrl>+<p> <Ctrl>+<q>


# docker ps -l

CONTAINER ID   IMAGE     COMMAND   CREATED              STATUS              PORTS     NAMES

7cf9311ecd3a   centos    "bash"    About a minute ago   Up About a minute             jovial_carver

# docker attach 7cf9311ecd3a   (To connect back to the container use the container ID)

# docker stop 7cf9311ecd3a   (to stop a container)

# docker kill 7cf9311ecd3a   (to kill a container)