part 3 docker build images and commit , delete and stop running containers

Docker image is made up of list of readonly layes that represent filesystem differences. image layers are stacked on top of each other to form up a base for container's filesystem

Install GIT in a base image called ubuntu:latest

# docker run -it ubuntu:latest
apt-get update && apt-get install -y git

exit

# docker ps -a     ...grab container id


Docker commit - Create a new image from a container's changes
## commit changes and save to a new container named ubuntu:1.00
docker commit 4188d246e83c urg3n/ubuntu:1.00

docker commit d823hjhd8fj2    repositoryname:tag

# list new images created
--> docker images

docker run -it urg3n/ubuntu:1.00

## Delete container !!! ##

docker ps -a   and grab container id

docker rm 247e45581fed    ### removes container with ID 247e45581fed

part 2 docker port mapping and run in background

## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100

## specify name for docker container we want to run
docker run  --name  mycontainer100 busybox:1.24
docker run  --name  mycontainer200 busybox:latest
docker ps -a

docker inspect containerid
##outpus image id , logpath,mac id

user1@localhost$ docker run -d busybox:latest sleep 10
a7393fc5cc8e1db7e87b9eb24151147

user1@localhost$ docker inspect a7393fc5cc8e1db7e87b9eb24151147


### docker tomcat
expose container port 8080 to host port 8888

docker run -it -p 8888:8080 tomcat:8.0

-->open browser--goto--> localhost:8888  it willopen tomcat server


# run container in detached mode

docker run -it -d -p 8888:8080 tomcat:8.0 

docker exec <name> /bin/cat /etc/profile
docker logs <name>

#docker run -d -p <hostport>:<containerPort>  nginx:latest

a7393fc5cc8e1db7e87b9eb24151147sf
docker logs a7393fc5cc8e1db7e87b9eb24151147sf

# Docker attach or login into the running container :-

docker exec -it containeridORname /bin/bash

# Docker management
# delete all containers
docker ps -aq | xargs docker rm -f

docker logs <cont id>   # view the output logs of container






mysql database size

To determine the sizes of all of your databases, at the mysql> prompt type the following command:

SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;


To determine the sizes of all of the tables in a specific database, at the mysql> prompt, type the following command. Replace database_name with the name of the database that you want to check:

SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;

git dealing with remotes

Add a remote

git remote add origin https://github.com/user/repo.git
# Set a new remote

git remote -v
# Verify new remote
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

Remove remote

git remote -v
# View current remotes
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)
destination  https://github.com/FORKER/REPOSITORY.git (fetch)
destination  https://github.com/FORKER/REPOSITORY.git (push)

git remote rm destination
# Remove remote
git remote -v
# Verify it's gone
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)



Rename the remote

git remote -v
# View existing remotes
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)

git remote rename origin destination
# Change remote name from 'origin' to 'destination'

git remote -v
# Verify remote's new name
destination  https://github.com/OWNER/REPOSITORY.git (fetch)
destination  https://github.com/OWNER/REPOSITORY.git (push)


remote add origin git@gitlab.com:urg3n/mailservice935dovecot.git

git push origin master

postfix firewall daemon postfwd

https://www.vooservers.com/technical-blog/rate-limit-outbound-mail-in-postfix/

DKIM on postfix and bind

Open dkim on postfix


yum install opendkim

## cp /etc/opendkim.conf{,.orig}
## vim /etc/opendkim.conf

AutoRestart             Yes
AutoRestartRate         10/1h
LogWhy                  Yes
Syslog                  Yes
SyslogSuccess           Yes
Mode                    sv
Canonicalization        relaxed/simple
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

Generate set of keys for your mydomain.com domain name:

## mkdir /etc/opendkim/keys/mydomain.com
## opendkim-genkey -D /etc/opendkim/keys/mydomain.com/ -d mydomain.com -s default
## chown -R opendkim: /etc/opendkim/keys/mydomain.com
## mv /etc/opendkim/keys/mydomain.com/default.private /etc/opendkim/keys/mydomain.com/default


add mydomain.com to OpenDKIM’s key table by adding the following record in /etc/opendkim/KeyTable

default._domainkey.mydomain.com mydomain.com:default:/etc/opendkim/keys/mydomain.com/default
next, edit /etc/opendkim/SigningTable and add the following record to OpenDKIM’s signing table:

*@mydomain.com default._domainkey.mydomain.com


And add your domain and your hostname as trusted hosts in /etc/opendkim/TrustedHosts  

127.0.0.1
mydomain.com
host.mydomain.com
assuming the domain in question is ‘mydomain.com’ and server’s hostname is set to ‘host.mydomain.com’

finally, edit your mydomain.com DNS zone and add the TXT record from

/etc/opendkim/keys/mydomain.com/default.txt

default._domainkey      IN      TXT     ( "v=DKIM1; k=rsa; "
          "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDApHRr7ZmXRaAB+RQRbP4VdMwIrIHIP18KFtXRsv/xpWc0Gix6ZXN13fcG03KNGKZo2PY+csPkGC5quDnH5V0JEhDZ78KcDWFsU6u4fr9ktVAdt6P7jWXjcyqdHOZ8+YN4cAeU4lRFNgQvdupIcByYwzPYMgBFHfJm9014HvRqhwIDAQAB" )  ; ----- DKIM key default for mydomain.com


Verify by 
## dig +short default._domainkey.mydomain.com TXT

CONFIGURE POSTFIX

In order to integrate OpenDKIM with Postfix we need to add the following few lines in /etc/postfix/main.cf:

smtpd_milters           = inet:127.0.0.1:8891
non_smtpd_milters       = $smtpd_milters
milter_default_action   = accept
milter_protocol         = 2

## service opendkim start
## chkconfig opendkim on
## service postfix restart





 ## cp /etc/opendkim.conf{,.orig}
## vim /etc/opendkim.conf

AutoRestart             Yes  #Automatically re-start on failures.  Use with caution; if the filter fails instantly after it starts, this can cause a tight fork(2) loop

AutoRestartRate         10/1h  # This is a string of the form n/t[u] where n is an integer limiting the count of restarts in the given interval and t[u] defines the time  inter‐
              val  through which the rate is calculated;

LogWhy                  Yes # If  logging is enabled (see Syslog below), issues very detailed logging about the logic behind the filter's decision to either sign a message or verify it
Syslog                  Yes

SyslogSuccess           Yes #Log via calls to syslog(3) additional entries indicating successful signing or verification of messages.

Mode                    sv   # Valid modes  are  s
              (signer)  and  v (verifier).  The default is sv except in test mode (see the opendkim(8) man page) in which case the default is v.  When signing
              mode is enabled, one of the following combinations must also be set: (a) Domain, KeyFile, Selector, no KeyTable, no SigningTable; (b)  KeyTable,
              SigningTable, no Domain, no KeyFile, no Selector; (c) KeyTable, SetupPolicyScript, no Domain, no KeyFile, no Selector.


Canonicalization        relaxed/simple   #  Selects the canonicalization method(s) to be used when signing messages.  When verifying, the message's DKIM-Signature: header  field  specifies
              the  canonicalization  method.   The recognized values are relaxed and simple as defined by the DKIM specification.  The default is simple.  The
              value may include two different canonicalizations separated by a slash ("/") character, in which case the first will be applied  to  the  header
              and the second to the body.


ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

policyd

yum install perl-Net-Server perl-Config-IniFiles perl-Cache-FastMmap perl-Mail-SPF php php-pdo php-mysqli
wget https://download.policyd.org/v2.0.14/cluebringer-v2.0.14.tar.bz2

tar xvfj cluebringer-v2.0.14.tar.bz2
cd cluebringer-v2.0.14/database/

for i in core.tsql access_control.tsql quotas.tsql amavis.tsql checkhelo.tsql checkspf.tsql greylisting.tsql
  do
  ./convert-tsql mysql $i
 done > policyd.sql




 create database policyd in mysql

  mysql policyd < policyd.sql


yum install perl-Net-Server perl-Config-IniFiles perl-Cache-FastMmap perl-Mail-SPF php php-pdo php-mysqli
wget https://download.policyd.org/v2.0.14/cluebringer-v2.0.14.tar.bz2

tar xvfj cluebringer-v2.0.14.tar.bz2
cd cluebringer-v2.0.14/database/

for i in core.tsql access_control.tsql quotas.tsql amavis.tsql checkhelo.tsql checkspf.tsql greylisting.tsql
  do
  ./convert-tsql mysql $i
 done > policyd.sql

 create database policyd in mysql

  mysql policyd < policyd.sql

mkdir /usr/local/lib/cbpolicyd
cp -r cbp /usr/local/lib/cbpolicyd
cp cbpadmin /usr/local/bin/
cp cbpolicyd /usr/local/sbin/
cp cluebringer.conf /etc/

mkdir /var/log/cbpolicyd
mkdir /var/run/cbpolicyd

yum install perl-Config-IniFiles-2.72-2.el6
wget ftp://195.220.108.108/linux/centos/6.9/os/x86_64/Packages/perl-List-MoreUtils-0.22-10.el6.x86_64.rpm
yum install perl-List-MoreUtils-0.22-10.el6.x86_64.rpm


mkdir /usr/local/lib/cbpolicyd
cp -r cbp /usr/local/lib/cbpolicyd
cp cbpadmin /usr/local/bin/
cp cbpolicyd /usr/local/sbin/
cp cluebringer.conf /etc/

mkdir /var/log/cbpolicyd
mkdir /var/run/cbpolicyd


postfix fall back relay

postfix per smtp-transport smtp_fallback_relay master.cf

I’d got multiple SMTP transports on my postfix server, but one of these send’s newsletters,
As we already seen this in real life of an mailadmin some servers got rate-limit’s setup, so only a specific
amount of mail is accepted in a specific timeframe.
To get these masses sent to these destinations in a adequate timeframe we need a fallback relay.
Due to the configuration of the destination server these will accept mails from other client IP’s than
the rate-limited server is and they would send an 450 temporary error.
Long speech short sin.
Here as always my config snippet from postfix master.cf (somewhere at line 40):
smtp      unix  -       -       -       -       50       smtp
        -o smtp_fallback_relay=relay01.bla.com
No magic. Really? 

DONT FORGET THE S**** TABSTOP IN FRONT of "-o smtp_fallback_relay="
Otherwhise you gonna get this:

how email works refresher

The SMTP protocol works like this:
1) A client connects to an SMTP server.
2) The SMTP server says “hello”
3) The client authenticates (if necessary) by logging in.
4) Now it’s time to send an email. First, the client sends a “MAIL FROM” command with the email address that is the reverse-path. This is the email address that would receive a bounce or delivery status notification.
Note: The "MAIL FROM" address becomes the "Return-Path" header.
The receiving server adds the "Return-Path" to the email. (Just like it adds the "Received" header.) Therefore, a mail-sending app should never explicitly add the "Return-Path" header. The correct way of specifying the "Return-Path" is to pass the correct email address to "MAIL FROM" (see below).
5) The client then sends one or more “RCPT TO” commands, each with a recipient email address. It doesn’t matter if the recipient is a “To” , “CC”, or “BCC”, all recipient email addresses are passed to the SMTP server via “RCPT TO” commands.
6) Finally, the MIME source of the email is sent with a “DATA” command.
Note: The MIME source has header fields for “From”, “To”, and “CC”. These are the email addresses that will be seen by the receiver of the email. The actual recipients are the email addresses passed via the RCPT TO commands. It’s possible to create an email such that the “To” header field contains “santa.claus@northpole.com”, but you pass actual email addresses in the RCPT TO commands. The person receiving such an email (if not filtered as SPAM) would scratch his/her head and wonder why he/she received an email addressed to Santa Claus.
There are two ways to specify the "Return-Path" (i.e. the email address passed in the "MAIL FROM" command within the SMTP protocol.
1) If sending email by passing an email object to a method such as mailman.SendEmail, then set the emailObject.BounceAddress property. This is the address passed in the "MAIL FROM" command. If BounceAddress is unset, then the email object's From address is used.
2) If sending email by passing the exact MIME string, such as via mailman.SendMime, then the "fromAddr" argument is used.
A Note about BackScatter:
Now that you understand Return-Path, you can understand a problem called BackScatter. When a spammer sends millions of emails, the scoundrel will often pass a real email address (harvested from a web page) to the MAIL FROM command. A certain percentage of those emails are (of course) sent to invalid email addresses. A mail server managed by someone without a good understanding SMTP might configure the server to send DSN's (Delivery Status Notifications) for all undelivered emails. The end result is that the unlucky email address used by the spammer gets mail-bombed with DSN's. A good mail server administrator should either turn off DSN's, or only send DSN's for email known to NOT be SPAM.

part 1 docker getting started

add your user to docker group
# usermod -a -G docker user1

to use docker commands as user1 without logging out of system, run below command as user1

~$ newgrp docker

docker provides many ways to run commands in containers
container are about running process
focusing on "docker run"

docker run ubuntu:latest  ls -lh /etc/postfix

# get inside docker

docker run -i -t ubuntu:latest
type exit to exit



## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100


## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100

## specify name for docker container we want to run
docker run  --name  mycontainer100 busybox:1.24
docker run  --name  mycontainer200 busybox:latest
docker ps -a

docker inspect containerid
##outpus image id , logpath,mac id

user1@localhost$ docker run -d busybox:latest sleep 10
a7393fc5cc8e1db7e87b9eb24151147

user1@localhost$ docker inspect a7393fc5cc8e1db7e87b9eb24151147