Mysql Invalid default date value if zeros

Step 1

mysql> show variables like 'sql_mode' ;
| sql_mode      | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION 
 
Step 2 
Add to mysqld.cnf
<pre lang="bash">
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Step 3
Restart mysql

Docker how-to see mounted volumes

# docker inspect -f "{{ .Mounts }}" aghayevcom
[{bind  /home/user/Projects /home   true rprivate} {bind  /home/user/Servers /opt   true rprivate}]

Progress bar in command line

Copying files using rsync with progress bar

apt-get install rsync;
rsync -ah --progress /path/to/source /path/to/destination

Run sql script to restore db with progress bar

apt-get install pv;
pv script.sql | mysql -h hostname -u username -p password database

How to use screen utility which is better than nohup

Step 1. As a result of running the command it takes you inside newly created session

screen -S sessionname

Step 2. Run your command and then press the combination below to exit the screen

Ctrl+A then D (after releasing Ctrl + A)

Step 3

screen -ls
Output:
There is a screen on:
	3132.sessionname	(01/27/2020 05:50:32 PM)	(Detached)

Step 4. To reconnect into existing session screen

screen -R 3132.sessionname

Step 5. To quit the screen session

screen -XS 3132 quit

How-to get size of some folder

du -sh /var
du -sh mysql/*
du -sh  .

Docker if you need to edit file on stopped docker

I had a problem with a container which wouldn’t start due to a bad config change I made. I was able to copy the file out of the stopped container and edit it. something like:

docker cp test-mysql:/etc/mysql/my.cnf .

Edit it and copy back

docker cp my.cnf test-mysql:/etc/mysql/my.cnf
docker start mysql
docker exec -ti mysql bash

Git reset local master to match remote master

git reset --hard origin/master

Build and run container from Dockerfile

Step 1 – Dockerfile

FROM debian:jessie
MAINTAINER user@server.com
RUN apt-get update
RUN apt-get install -y vim
RUN apt-get install -y apache2
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server
RUN apt-get install -y php5
RUN apt-get install php5-mysql
RUN apt-get autoremove
 
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
 
EXPOSE 80
# Launch all services
# CMD ["apache2ctl", "-D", "FOREGROUND"]
COPY startup.sh /
RUN chmod 777 /startup.sh
CMD ["bash","/startup.sh"]

Step 2 – Create startup.sh

cat > startup.sh
#!/bin/bash
 
apache2ctl -D FOREGROUND

Step 3 – Building image

docker build -t aghayevcomdockerfile:latest .

Step 4 – Check if image was created

REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
aghayevcomdockerfile   latest          19e27a7ca24b        11 minutes ago      389MB
debian                 jessie              5d7d9c6338e8        3 weeks ago         129MB

Step 5 – Creating container

docker run -d -t -p 80:80 -p 443:443 -p 3306:3306 -v /home/user/Projects:/home -v /home/user/Servers:/opt --name aghayevcom aghayevcomdockerfile:latest

Step 6 – Check if container created

CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                NAMES
8946f43f47ea        aghayevcomdockerfile:version1.0   "bash /startup.sh"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   aghayevcom
 
p.s. Pay attention to COMMAND column, it should show which command will run first when u start container. In case of direct call of apache2ctl it shows this
#850703e85940        aghayevcomdockerfile:version1.0   "apache2ctl -D FOREG…"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   aghayevcom

Step 6 – Run container

docker start aghayevcom
 
p.s. It is possible to start container by direct calling Container ID
# docker start 8946f43f47ea

How to mount and unmount remote directory

Mounting

mkdir ~/remoteDir
ssh-keygen -t rsa
ssh-copy-id -i .ssh/id_rsa.pub user@hostname
sudo apt install sshfs
sshfs user@hostname:/ ~/remoteDir

Unmounting

fusermount -u ~/remoteDir

Apt sources.list to add or remove deb installation repositories

vi /etc/apt/sources.list