images


Bulk convert PNG images to JPG / JPEG

for i in *.png ; do convert "$i" "${i%.*}.jpg" ; done

The command “for i in .png ; do convert “$i” “${i%.}.jpg” ; done” is a Bash script that converts all PNG files in the current directory to JPEG files.

Let’s break down this command:

  • “for i in *.png ;” is a loop that iterates over each PNG file in the current directory.
  • “$i” is the name of the current PNG file being processed.
  • “convert” is a command-line tool that is part of the ImageMagick software suite. It is used for image conversion, resizing, and manipulation.
  • “${i%.}.jpg” is the new filename that the PNG file will be converted to. The “${i%.}” syntax is used to remove the file extension from the original PNG file name, leaving just the base filename, which is then followed by “.jpg” to indicate that the new file should be a JPEG file.

In summary, this command converts each PNG file in the current directory to a JPEG file with the same base filename. For example, “example.png” would be converted to “example.jpg”. This command can be useful when you have a large number of PNG files that you need to convert to JPEG format quickly and easily.


Bind for 0.0.0.0:443 failed: port is already allocated

On a Docker installation that we have, we updated the image files for our containers using the following command:

docker images --format "{{.Repository}}:{{.Tag}}" | grep ':latest' | xargs -L1 docker pull;

Then we tried to update our container, as usual, using the docker-compose command.

export COMPOSE_HTTP_TIMEOUT=180; # We extend the timeout to ensure there is enough time for all containers to start
docker-compose up -d --remove-orphans;

Unfortunately, we got the following error:

export COMPOSE_HTTP_TIMEOUT=180;
docker-compose up -d --remove-orphans;

Starting entry ... 
Starting entry ... error

ERROR: for entry  Cannot start service entry: driver failed programming external connectivity on endpoint entry (d3a5d95f55c4e872801e92b1f32d9693553bd553c414a371b8ba903cb48c2bd5): Bind for 0.0.0.0:443 failed: port is already allocated

ERROR: for entry  Cannot start service entry: driver failed programming external connectivity on endpoint entry (d3a5d95f55c4e872801e92b1f32d9693553bd553c414a371b8ba903cb48c2bd5): Bind for 0.0.0.0:443 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

We used the docker container ls command to check which container was hoarding port 443, but none was doing so. Because of this, we assumed that docker ran into a bug. The first step we took (and the last) which solved the problem was to restart the docker service as follows:

sudo service docker restart;

This command was enough to fix our problem without messing with docker further.


ERROR: for container_a UnixHTTPConnectionPool(host=’localhost’, port=None): Read timed out. (read timeout=60)

There is this docker server that we have access to, which probably due to lousy planning, we put way too many containers on it. The server does not have SSD disks, and for that reason, whenever there are too many IO operations, it becomes unresponsive. When we mass update all containers by updating the images using the following command and then issuing a fresh docker-compose, we get a lot of time-out errors.

The commands we use to update the images and recreate our containers using the new images are the following:
(Please note that these commands need to execute from the folder where the file docker-compose.yml resides)

#Update all docker images that have the 'latest' tag
docker images --format "{{.Repository}}:{{.Tag}}" | grep ':latest' | xargs -L1 docker pull;
#Rebuild all containers using the new images.
docker-compose up -d;

After executing the second command, we often get many copies of the following error:

ERROR: for container_a  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

This error indicates that the recreate command was waiting for too long for the docker daemon to respond with no success. At the end of the output, we can see that it was waiting for 60 seconds.

At the end of the output, we get the following information and advice:

ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).

Following the advice, we used the following command to overwrite the value of the COMPOSE_HTTP_TIMEOUT variable to a more significant number.

#Increase timeout period to 120 seconds.
export COMPOSE_HTTP_TIMEOUT=120;
#Rebuild all containers using the new images.
docker-compose up -d;

Doing so, we were able to rebuild all containers without reissuing many times the up command.

Sidenote

This server really does have a lot of containers, we had to create the file /etc/docker/daemon.json so that we would have enough network addressing space to handle all the bridges and sub-networks.

The contents of /etc/docker/daemon.json are:

{
  "default-address-pools": [
    {
      "base": "172.80.0.0/16",
      "size": 24
    },
    {
      "base": "172.90.0.0/16",
      "size": 24
    }
  ]
}

The above configuration solved the following problem for us:

ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

Images, that are not visible initially, don’t show with Customizr Pro theme

Recently we were investigating an issue on a live website at which some images were not loading. After some testing we saw that only pictures that were visible while loading the page were being loaded as well. Checking the console we found the following JS error:

Uncaught TypeError: a.browser is undefined    jQuery 2
jquery.fancybox-1.3.4.min.js:1:205
NOK => browserDetect::addBrowserClassToBody => TypeError: t.browser is undefined tc-scripts.min.js:1:81903

We did not want to waste time on debugging this so we disabled the Load images on scroll option to get the site live asap. To do so, first we clicked on the Customize button on the admin bar:

Once the menu loaded, we clicked on the Advanced Options button:

From there, we clicked on Website Performances :

And got the following options

As seen in the image below, we disabled (among other changes) the option Load images on scroll

After pressing the Publish button, we reloaded the site, the JavaScript error was still there but the images were loading as expected.