WittCode💻

Pick the Right Docker Image!

By

Some Docker images are too big, some don't have the right architecture, but some are just right. Take your time to pick the right one. Compare the Ubuntu base image to Alpine.

Table of Contents 📖

Docker Image Sizes

For a while now I have been using Ubuntu as the base image for running Cron jobs on my blog website. Specifically, I have a cron job that backups up my database every hour. However, the Ubuntu Docker image is not a small image and using it for Cron jobs is definitely over the top. Check out some of the stats below.

docker images

REPOSITORY TAG       IMAGE ID       CREATED          SIZE
ubuntu     1.3.0     dde6c7772fe5   13 days ago    282MB
docker stats --no-stream

CONTAINER ID   NAME              CPU %     MEM USAGE / LIMIT   MEM %     NET I/O           BLOCK I/O         PIDS
73152c532c63   cron              0.00%     47.68MiB / 1GiB     4.66%     57kB / 0B         123MB / 2.69GB    2

Not to mention, my blog website is running on a small VPS of 1GB RAM, 1 CPU, etc. Basically nothing to write home about.

free -h
              total        used        free      shared  buff/cache   available
Mem:           1.0G        513M        5.8M        4.4M        504M        505M
Swap:          256M         32M        223M

What I Did

Every now and then I go back to my blog website and update it with new technologies and methods that I have learned. Recently, I have been looking at minimizing the impact my Docker containers have on the small resources available to me. The first obvious one was to downsize the Cron container. For that, I switched over to Alpine.

INFO: Docker Alpine is a lightweight Linux distribution. One reason Alpine is so lightweight is that it comes with minimal utilities pre-installed. This also makes Alpine more secure as it lowers the attack surface. We can check the size of the Alpine image by spinning up a container and using docker ps.

Now check out the Docker statistics for using this new image size.

docker images

REPOSITORY             TAG       IMAGE ID       CREATED          SIZE
alpine                 2.0.0     2009b837ad48   28 minutes ago   10.2MB
docker stats --no-stream
  
CONTAINER ID   NAME              CPU %     MEM USAGE / LIMIT   MEM %     NET I/O           BLOCK I/O         PIDS
5997e82d054b   wb-cron-c         0.00%     2.66MiB / 1GiB      0.26%     698B / 0B         0B / 0B           1