Windows 10: multi-line Git Commit messages.

In Windows 10, how to do multi-line messages for a Git commit.

On Windows 10, my git CLI version is 2.37.3.windows.1. I am describing how do multi-line messages for a Git commit.

A git commit command, can take one (1) or two (2) text parameters, like so:

git commit -m "First message."

git commit -m "First message." -m "Detail description."

We can make “Detail description.” a multi-line description as in the following example: we check in D:\learn-git>some_js_funcs.js, we have to issue 3 (three) commands:

⓵ First command, add the file to be checked in (i.e. committed):

D:\learn-git>git add some_js_funcs.js

⓶ Second command, commit with a multi-line description:

D:\learn-git>git commit -m "Major refactoring." -m "Added:"^

"function runAjax( method, ..., errorCallback )."^

"const onAjaxErrorUseDialog = ( xhr, error, errorThrown ) => displayError( xhr, error, errorThrown );"^

"const onAjaxErrorUseForm = ( xhr, error, errorThrown ) => setFormErrorText( errorThrown );"^

""^

"Removed:"^

"function retrieveData( method, endPoint, csrfToken, data, successCallback )"^

"function saveData( endPoint, csrfToken, data, successCallback )"^

""^

"function jsonViewerDialog( jsonData, params ) moved to fullscreen_dialogs.js."^

""^

"Bug fixed:"^

"function clearFormInfoText() -- set '#firstMsg' to ' ' instead of blank."

It should be apparent that we prepare this command in a text editor, and just copy and paste this command to the command line console. Note that:

  • Each message is enclosed within a pair of double quotes, i.e. "function runAjax( method, ..., errorCallback )."^.
  • There is a caret ^ character at the end of each line, except the last line.
  • THERE MUST BE NOTHING ELSE AFTER THE caret ^ character. A single space did cause a problem for me.
  • ""^ inserts a blank line into the Git commit description.
  • There is a blank line follows each text line, again except the last line.

⓷ Third and last command, push to the remote repo:

D:\learn-git>git push -u origin main

The second command will pause twice for our input. The first phase, we just click on the Paste anyway button, the second phase, we just hit the Enter key — please see illustrations:

The multi-line description as seen in the repo UI:

I took me a few tries to get this working on Windows 10: I document so if I forget, I can look it up later… This would not work on a Linux environment, or at least I have not tested yet. Thank you for reading, I hope you find this useful. Stay safe as always.

Using PostgreSQL Official Docker image on Windows 10 and Ubuntu 22.10 kinetic.

Discussing a basic set up process to use the PostgreSQL Official Docker image on Windows 10 Pro, and Ubuntu 22.10 kinetic running on an older HP laptop. Then backup a PostgreSQL database on Windows 10 Pro machine, and restore this backup database to the newly set up Docker PostgreSQL Server 15.1 on the Ubuntu 22.10 machine.

The PostgreSQL Server Docker official images are at this address postgres Docker Official Image.

This is the full documentation for these images. Please note, this page has links to Docker official documents on volumes, etc., which are necessary to run images such as this.

This post also makes use of PostgreSQL Server password file, whose official documentation is 34.16. The Password File.

The objectives of this post are rather basic. ❶, getting the Docker container to store the data in a specific location on the host, of my own choosing. ❷, implementing the password file on the host and pass it to the Docker container as per official documentation above.

Of course, the final goal is to connect to a PostgreSQL server running in a Docker container with whatever clients we need.

Table of contents

Downloading and Storing the Image Locally

To download:

E:\docker-images>docker pull postgres:latest

To save the image locally to E:\docker-images\:

E:\docker-images>docker save postgres:latest --output postgres-latest.tar

postgres-latest.tar is also used in Ubuntu 22.10 later on. This Docker image contains PostreSQL Server version 15.1 (Debian 15.1-1.pgdg110+1).

Environments

  1. PostreSQL Server Docker official image — version 15.1 (Debian 15.1-1.pgdg110+1).
  2. Windows 10 Pro — version 10.0.19045 Build 19045.
  3. Ubuntu — version 22.10 kinetic. The machine it runs on is an older HP Pavilion laptop. The name of this machine is HP-Pavilion-15, the rest of this post will use this name and Ubuntu 22.10 interchangeably.
  4. Windows 10 pgAdmin 4 — version 6.18. Older versions might not work: when trying to connect, they fail with different errors.
  5. On Windows 10, “docker” CLI ( Docker Engine ) — version 20.10.17.
  6. On Ubuntu 22.10, “docker” CLI ( Docker Engine )version 20.10.22.

On Windows 10

Since I already have PostgreSQL Server 14 installed on Windows 10 Pro, I have to turn its service process off, before setting up another server in Docker container.

❶ I select to store PostgreSQL data in D:\docker_data\postgresql\. After creating this directory path, on the docker run command, it can be mounted as:

--mount type=bind,source=//d/docker_data/postgresql,target=/var/lib/postgresql/data

My trial and error runs show that the host directory, which is D:\docker_data\postgresql\ translated to //d/docker_data/postgresql in this case, must be COMPLETELY empty, otherwise Docker raises an error.

The image has already been loaded when first pulled. The run command is:

docker run -d -it -p 5432:5432 --name postgresql-docker -e POSTGRES_PASSWORD=pcb.2176310315865259 --mount type=bind,source=//d/docker_data/postgresql,target=/var/lib/postgresql/data postgres:latest

❷ Now, stop and remove the postgresql-docker container:

C:\>docker stop postgresql-docker
C:\>docker rm postgresql-docker

Verify that container postgresql-docker has been removed, run:

C:\>docker ps -a

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

I have no other containers, your list is likely to be different. We should be able to confirm that postgresql-docker is not in the list anymore.

Initial PostreSQL Server files and folders should now be created under D:\docker_data\postgresql\, around 23 ( twenty three ) items, most are folders.

❸ Now create password file secrets\pgpass.conf under D:\docker_data\postgresql\:

🐘 Content of D:\docker_data\postgresql\secrets\pgpass.conf:

localhost:5432:postgres:postgres:pcb.2176310315865259

As per official documentation, the password file is passed to the container as:

-e POSTGRES_PASSWORD_FILE=/var/lib/postgresql/data/secrets/pgpass.conf

Recall that /var/lib/postgresql/data/ is the host translated directory //d/docker_data/postgresql in the first mount:

--mount type=bind,source=//d/docker_data/postgresql,target=/var/lib/postgresql/data

❹ The final command is, then:

docker run -d -it -p 5432:5432 --name postgresql-docker --mount type=bind,source=//d/docker_data/postgresql,target=/var/lib/postgresql/data -e POSTGRES_PASSWORD_FILE=/var/lib/postgresql/data/secrets/pgpass.conf postgres:latest

Please note that,I have to do two ( 2 ) commands to get the password file to work. I did try to run only the final command on the empty //d/docker_data/postgresql, it did not work. Please try for yourself.

The obvious question is, can we store the password file in a directory other than the mounted host data directory D:\docker_data\postgresql\? I don’t know if it is possible, if it is possible, then I don’t know how to do it yet.

To connect pgAdmin 4 to the just set up Docker PostgresSQL Server 15.1, register a new server as:

  1. Host name/address: localhost
  2. Port: 5432.
  3. Username: postgres — I am using the default as per official document.
  4. Password: pcb.2176310315865259

Please note, the Windows 10 version of pgAdmin 4 is 6.18. Older versions might not work: when trying to connect, they fail with different errors.

Docker PostgresSQL Server 15.1 is now ready in Windows 10.

On Ubuntu 22.10 kinetic

On Ubuntu 22.10, I did not do any of the trial and error runs as Windows 10. I assume that, what do not work on Windows 10, will also not work on Ubuntu 22.10.

❶ Copy the image to /home/behai/Public/docker-images/, then load the image with:

behai@HP-Pavilion-15:~$ sudo docker load --input /home/behai/Public/docker-images/postgres-latest.tar

❷ I want to store data under /home/behai/Public/database/postgresql/, create the directories database/postgresql/ under /home/behai/Public/, and run the first command:

$ sudo docker run -d -it -p 5432:5432 --name postgresql-docker -e POSTGRES_PASSWORD=pcb.2176310315865259 --mount type=bind,source=/home/behai/Public/database/postgresql,target=/var/lib/postgresql/data postgres:latest

❸ Then stop and remove the postgresql-docker container:

behai@HP-Pavilion-15:~$ sudo docker stop postgresql-docker
behai@HP-Pavilion-15:~$ sudo docker rm postgresql-docker

Verify that the Docker container postgresql-docker has been removed:

behai@HP-Pavilion-15:~$ sudo docker ps -a

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Even if the list is not empty, postgresql-docker should not be in the container list.

Initial PostreSQL Server files and folders should now be created under /home/behai/Public/database/postgresql/:

❹ Now create secrets/pgpass.conf under /home/behai/Public/database/postgresql/:

🐘 Content of /home/behai/Public/database/postgresql/secrets/pgpass.conf:

localhost:5432:postgres:postgres:pcb.2176310315865259

The password file is passed to the Docker container as:

-e POSTGRES_PASSWORD_FILE=/var/lib/postgresql/data/secrets/pgpass.conf

/var/lib/postgresql/data/ is the host directory /home/behai/Public/database/postgresql/ in the first mount:

--mount type=bind,source=/home/behai/Public/database/postgresql,target=/var/lib/postgresql/data

Final command:

$ sudo docker run -d -it -p 5432:5432 --name postgresql-docker --mount type=bind,source=/home/behai/Public/database/postgresql,target=/var/lib/postgresql/data -e POSTGRES_PASSWORD_FILE=/var/lib/postgresql/data/secrets/pgpass.conf postgres:latest

Updated on 16/01/2023 — open port 5432 for external access:

$ sudo ufw allow from any to any port 5432 proto tcp

Since this is a development environment, there is no IP address restriction applied, in a production environment, I imagine only certain IP addresses are allowed. Please be mindful of this.

16/01/2023 update ends.

From Windows 10, to connect pgAdmin 4 to Docker PostgresSQL Server 15.1 running on HP-Pavilion-15, register a new server:
  1. Host name/address: HP-Pavilion-15 — it’s better to use the machine name, since IP addresses can change.
  2. Port: 5432.
  3. Username: postgres — I am using the default as per official document.
  4. Password: pcb.2176310315865259

Please note, the Windows 10 version of pgAdmin 4 is 6.18. Older versions might not work: when trying to connect, they fail with different errors.

Backup and Restore a Database

I already have PostgreSQL Server 14 installed on Windows 10 Pro. I back up a development database ompdev from this server, and restore the backup data to Docker PostgreSQL Server 15.1 running on Ubuntu 22.10: machine name HP-Pavilion-15.

The database backup command:

"C:\Program Files\PostgreSQL\14\bin\pg_dump.exe" postgresql://postgres:top-secret@localhost/ompdev > ompdev_pg_database.sql

Please note, the above command will not have the create database statement in the dump file, on the target server, we need to manually create a database to restore to.

Restoring to HP-Pavilion-15 involves two simple steps.

⓵ Connect pgAdmin 4 to Docker PostgreSQL Server on HP-Pavilion-15, as discussed. Then create a new database with:

CREATE DATABASE ompdev;

Please note, it does not have to be pgAdmin 4, we can use any other client tools available.

⓶ Then run the following restore command:

"C:\Program Files\PostgreSQL\14\bin\psql.exe" postgresql://postgres:pcb.2176310315865259@HP-Pavilion-15/ompdev < ompdev_pg_database.sql

If everything goes well, we should now have the database restored and ready for connection on Docker PostgreSQL Server 15.1 running on Ubuntu 22.10. The below screen capture showing the ompdev database restored on HP-Pavilion-15:

Other Docker Posts Which I’ve Written

  1. Docker Compose: how to wait for the MySQL server container to be ready? — Waiting for a database server to be ready before starting our own application, such as a middle-tier server, is a familiar issue. Docker Compose is no exception. Our own application container must also wait for their own database server container ready to accept requests before sending requests over. I’ve tried two ( 2 ) “wait for” tools which are officially recommended by Docker. I’m discussing my attempts in this post, and describing some of the pending issues I still have.
  2. Synology DS218: unsupported Docker installation and usage… — Synology does not have Docker support for AArch64 NAS models. DS218 is an AArch64 NAS model. In this post, we’re looking at how to install Docker for unsupported Synology DS218, and we’re also conducting tests to prove that the installation works.
  3. Python: Docker image build — install required packages via requirements.txt vs editable install. — Install via requirements.txt means using this image build step command “RUN pip3 install -r requirements.txt”. Editable install means using the “RUN pip3 install -e .” command. I’ve experienced that install via requirements.txt resulted in images that do not run, whereas using editable install resulted in images that do work as expected. I’m presenting my findings in this post.
  4. Python: Docker image build — “the Werkzeug” problem 🤖! — I’ve experienced Docker image build installed a different version of the Werkzeug dependency package than the development editable install process. And this caused the Python project in the Docker image failed to run. Development editable install means running the “pip3 install -e .” command within an active virtual environment. I’m describing the problem and how to address it in this post.
  5. Python: Docker image build — save to and load from *.tar files. — We can save Docker images to local *.tar files, and later load and run those Docker images from local *.tar files. I’m documenting my learning experimentations in this post.
  6. Python: Docker volumes — where is my SQLite database file? — The Python application in a Docker image writes some data to a SQLite database. Stop the container, and re-run again, the data are no longer there! A volume must be specified when running an image to persist the data. But where is the SQLite database file, in both Windows 10 and Linux? We’re discussing volumes and where volumes are on disks for both operating systems.
  7. Docker on Windows 10: running mysql:8.0.30-debian with a custom config file. — Steps required to run the official mysql:8.0.30-debian image on Windows 10 with custom config file E:\mysql-config\mysql-docker.cnf.
  8. Docker on Windows 10: mysql:8.0.30-debian log files — Running the Docker Official Image mysql:8.0.30-debian on my Windows 10 Pro host machine, I want to log all queries, slow queries and errors to files on the host machine. In this article, we’re discussing how to go about achieving this.
  9. pgloader Docker: migrating from Docker & localhost MySQL to localhost PostgreSQL. — Using the latest dimitri/pgloader Docker image build, I’ve migrated a Docker MySQL server 8.0.30 database, and a locally installed MySQL server 5.5 database to a locally installed PostgreSQL server 14.3 databases. I am discussing how I did it in this post.

Thank you for reading and stay safe as always.

Docker on Windows 10: mysql:8.0.30-debian log files

Running the Docker Official Image mysql:8.0.30-debian on my Windows 10 Pro host machine, I want to log all queries, slow queries and errors to files on the host machine. In this article, we’re discussing how to go about achieving this.

We’ve previously discussed how to implement a custom config file for MySQL Docker Official Image in Docker on Windows 10: running mysql:8.0.30-debian with a custom config file. This post assumes that we are using this custom config file.

What I would like to do is to log all queries, slow queries and errors to files on the host machine. The official references to each of the log types:

Accordingly, the custom config file E:\mysql-config\mysql-docker.cnf gets updated as:

[mysqld]
default_authentication_plugin=mysql_native_password
log_bin_trust_function_creators=1

# Below contents are updated contents.

# General and slow logging.
log_output=FILE

general_log=1
general_log_file="/var/lib/mysql/general_log.log"

slow_query_log=1
slow_query_log_file="/var/lib/mysql/slow_query.log"
long_query_time=10
log_queries_not_using_indexes=1

# Error Logging.
log_error="/var/lib/mysql/error.err"

I updated it directly on Windows, its permissions get changed, and as discussed in Docker on Windows 10: running mysql:8.0.30-debian with a custom config file, we need to change its permissions to the correct ones.

While mysql-docker mysql:8.0.30-debian container is running, start the interactive mode with the Bash process to change config file permissions:

E:\>docker exec -it mysql-docker bash

root@8e6656b15d9a:/# cd /etc/mysql/conf.d/
root@8e6656b15d9a:/# chmod u+rw-x mysql-docker.cnf
root@8e6656b15d9a:/# chmod g+r-wx mysql-docker.cnf
root@8e6656b15d9a:/# chmod o+r-wx mysql-docker.cnf

Permissions should now be correct. To verify:

root@8e6656b15d9a:/# ls -l

total 4
-rw-r--r-- 1 root root 380 Oct 20 11:40 mysql-docker.cnf

Restart mysql-docker container for the new settings to take effect:

E:\>docker stop mysql-docker
E:\>docker start mysql-docker

Please note, for the above two ( 2 ) commands to work, mysql-docker must be started without the –rm flag, that is:

docker run -d -it --name mysql-docker -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pcb.2176310315865259 --mount type=bind,source=//e/mysql-config,target=/etc/mysql/conf.d --mount source=mysqlvol,target=/var/lib/mysql mysql:8.0.30-debian

Please also notice the following option in the above docker run command: –mount source=mysqlvol,target=/var/lib/mysql. We shall come back to this option later on.

Using a client tool such as MySQL Workbench to verify that the new settings are effective:

show variables like 'general_log';
show variables like 'slow_query_log';
show variables like 'log_queries_not_using_indexes';

The above commands should each return ON. Similarly, the below should each return the corresponding values we set in the config file:

show variables like 'general_log_file';
show variables like 'slow_query_log_file';
show variables like 'log_error';

➡️ But where /var/lib/mysql/general_log.log, /var/lib/mysql/slow_query.log and /var/lib/mysql/error.err are?

In Python: Docker volumes — where is my SQLite database file?, I’ve discussed where Docker volumes or data files are on Windows 10 Pro host machine: essentially, due to the installation of my Docker Desktop uses Windows Subsystem for Linux ( WSL 2 ) based engine, I can copy and paste this directory:

\\wsl$\docker-desktop-data\version-pack-data\community\docker

to Windows File Explorer, and it should go to the top level Docker desktop data directory; mysql-docker‘s files are in:

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\mysqlvol\_data

We should find our log files:

Why \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\mysqlvol?

Recall the docker run option previously mentioned –mount source=mysqlvol,target=/var/lib/mysql? source=mysqlvol is the host machine volume or where the container’s data files live.

Logging all queries can slow down the server, and the log file can get very big, it should only be used during development, certainly not in production. Also, these options can be set and reset on the flight without needing to use the config file or server restart. For example, via MySQL Workbench:

SET GLOBAL general_log = 'OFF';
SET GLOBAL general_log = 'ON';

I’ve tried, and it works: I can turn off general_log, then delete the log file, turn on general_log again, and a new log file is created.

I do hope you find this helpful and useful. Thank you for reading and stay safe as always.

Docker on Windows 10: running mysql:8.0.30-debian with a custom config file.

Steps required to run the official mysql:8.0.30-debian image on Windows 10 with custom config file E:\mysql-config\mysql-docker.cnf.

I want to use my custom config file E:\mysql-config\mysql-docker.cnf, when running the Docker Official Image mysql:8.0.30-debian, on my Windows 10 Pro machine. I’m describing the steps to get this working.

mysql-docker.cnf is the only file in E:\mysql-config\. Its content:

[mysqld]
default_authentication_plugin=mysql_native_password
log_bin_trust_function_creators=1

❷ For this mysql:8.0.30-debian image, the custom config file is /etc/mysql/conf.d/mysql.cnf.

Its permissions are: owner has read and write; groups and others has only read. Our own custom config file must have the same permissions.

❸ Mount E:\mysql-config\mysql-docker.cnf to change its permissions, we only need the directory. E:\mysql-config\ gets translated to //e/mysql-config. The mounting option is thus:

--mount type=bind,source=//e/mysql-config,target=/etc/mysql/conf.d

The command to run:

E:\>docker run -d -it --rm --name mysql-docker --mount type=bind,source=//e/mysql-config,target=/etc/mysql/conf.d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pcb.2176310315865259 mysql:8.0.30-debian

Run the container in the interactive mode with the bash process to change config file permissions:

E:\>docker exec -it mysql-docker bash

Verify that we’re looking at the Windows 10 Pro directory, which has only this config file, also note its permissions:

root@5b671d85c90b:/# ls -l /etc/mysql/conf.d

total 4
-rwxrwxrwx 1 root root 95 Aug  8 11:41 mysql-docker.cnf

Change permissions to match the corresponding container custom config file. That is, owner has read and write; groups and others has only read:

root@5b671d85c90b:/# cd /etc/mysql/conf.d/
root@5b671d85c90b:/# chmod u+rw-x mysql-docker.cnf
root@5b671d85c90b:/# chmod g+r-wx mysql-docker.cnf
root@5b671d85c90b:/# chmod o+r-wx mysql-docker.cnf

Permissions should now be correct. To verify:

root@5b671d85c90b:/# ls -l

total 4
-rw-r--r-- 1 root root 95 Aug  8 11:41 mysql-docker.cnf

❹ Stop and re-run to verify the custom config file takes effects. This time, also run with proper data persistent volume with the option:

--mount source=mysqlvol,target=/var/lib/mysql

The commands to stop the container and to run are:

E:\>docker stop mysql-docker
E:\>docker run -d -it --rm --name mysql-docker -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pcb.2176310315865259 --mount type=bind,source=//e/mysql-config,target=/etc/mysql/conf.d --mount source=mysqlvol,target=/var/lib/mysql mysql:8.0.30-debian

❺ Verify custom config takes effect. Using the MySQL command line to query values of the custom options. Run the interactive bash shell:

E:\>docker exec -it mysql-docker bash

Launch MySQL command line:

root@dfa641fecc0a:/# mysql -uroot -ppcb.2176310315865259

⓵ Verify default_authentication_plugin=mysql_native_password:

mysql> show variables like 'default_authentication_plugin';

+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | mysql_native_password |
+-------------------------------+-----------------------+
1 row in set (0.01 sec)

⓶ Verify log_bin_trust_function_creators=1. Please note, 1 is reported as ON:

mysql> show variables like 'log_bin_trust_%';

+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | ON    |
+---------------------------------+-------+
1 row in set (0.00 sec)

❻ Using a Windows MySQL client tool, we should also be able to connect to MySQL in the mysql-docker container. E.g.:

"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql" --protocol=TCP --host=localhost --port=3306 --user=root --password=pcb.2176310315865259

Since the value of default_authentication_plugin is mysql_native_password we should login successfully. I.e. we should not get the error:

ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password’ cannot be loaded: The specified module could not be found. .

✿✿✿

It took me a while to work this one out… I document it so that it could possibly be of some helps for others. I am actually using mysql:8.0.30-debian as my development server. I’ll do more documents on it later on. I hope you find this helpful and thank you for reading.

Design a site like this with WordPress.com
Get started