What are you trying to optimize?

There are three utilities available to optimize images, one for each respective image format. Each need to be installed manually on the Docker container hosting your WordPress instance.

JPG

JPG is a file extension for a lossy graphics file. … JPEG stands for Joint Photographic Experts Group who created the standard. JPG files have 2 sub-formats, JPG/Exif (often used in digital cameras and photographic equipment), and JPG/JFIF (often used on the World Wide Web).

jpegoptim is used to optimize JPG files and supports lossless optimization.

Installation

Log on to the server hosting your Docker containers and run these from PowerShell:

docker exec -it ContainerName bash
apt-get update -y
apt-get install jpegoptim -y

Next, navigate to a directory where your images are located.

cd /var/www/html/wp-content/uploads/2019/11

There are several options available for jpegoptim. If you want to give lossless optimization a try, run this:

jpegoptim *.jpg

I found that these settings gave me the best results and freed up a lot of disk space:

jpegoptim *.jpg --strip-all --max=90

PNG

Portable Network Graphics is a raster-graphics file-format that supports lossless data compression. PNG was developed as an improved, non-patented replacement for Graphics Interchange Format. PNG supports palette-based images, grayscale images, and full-color non-palette-based RGB or RGBA images.

OptiPNG is used to optimize PNG files and supports lossless optimization.

Installation

Log on to the server hosting your Docker containers and run these from PowerShell:

docker exec -it ContainerName bash
apt-get update -y
apt-get install optipng -y

Next, navigate to a directory where your images are located.

cd /var/www/html/wp-content/uploads/2019/11

Unlike jpegoptim which has multiple options when it comes to optimizing the file, OptiPNG does not and only lossless optimization is available.

optipng *.png

GIF

GIF, or Graphic Interchange Format, is a file extension for an often animated raster graphics file and is the second most common image format used on the World Wide Web after JPEG. GIF uses the LZW compression algorithm and is owned by Unisys.

Gifsicle is used to optimize GIF files that supports lossless optimization.

Installation

Log on to the server hosting your Docker containers and run these from PowerShell:

docker exec -it ContainerName bash
apt-get update -y
apt-get install gifsicle -y

Next, navigate to a directory where your images are located.

cd /var/www/html/wp-content/uploads/2019/11

Unlike jpegoptim which has multiple options when it comes to optimizing the file, gifsicle does not and only lossless optimization is available.

gifsicle *.gif

Have fun optimizing 🙂

Note: this will also work on an AWS Bitnami EC2 instance.