Docker-based fio benchmarking - Part Two

Docker-based fio benchmarking - Part Two
Photo by Glen Rushton / Unsplash

In this article, we will build a docker image which is based on python versioned alpine Linux. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

In the python versioned alpine Linux image, we can add additional packages to support our python script "". The following is the Dockerfile we will use to build the docker image.

cat Dockerfile
FROM python:3-alpine

RUN apk add --no-cache \
    bash \
    sudo \
    lsblk \
    util-linux \
    procps \

COPY perfbench/ /

Now that we have Dockerfile defined, we can build the docker image as below.

$ docker build -t perfbench .

$ docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
perfbench                            latest              fb9441429ea1        21 minutes ago      61.2MB
python                               3-alpine            08d07b62c1c9        2 days ago          48.6MB

Detached mode

To start a container in detached mode, we can use the -d option.

$ docker run -t -d --privileged --name myperfbench -v /data:/data perfbench

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
3473aa8332cb        perfbench            "python3"                4 seconds ago       Up 3 seconds                                      myperfbench

$ docker exec -it myperfbench bash
bash-5.1# cat /etc/alpine-release
bash-5.1# python --version
Python 3.10.2


  1. Adding the "-t" flag prevents the container from exiting when running in the background. It allocates a pseudo-tty. You would see the following issue if it's not specified.

    $ docker run -d --name myperfbench perfbench
    $ docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                         NAMES
    ed997c56e9e9        perfbench            "python3"                6 seconds ago       Exited (0) 4 seconds ago                                 myperfbench
  2. Using "--privileged" flag to give extended privileges to the container. For example, we can drop cache inside the container with this privilege.

Foreground mode

For interactive processes (like a shell), you must use -i -t together in order to allocate a tty for the container process.

$ docker run -it --rm --privileged --name myperfbench -v /data:/data perfbench bash

$ docker run --rm --privileged --name myperfbench -v /data:/data perfbench bash -c "python --dir /data --logdir /data/result"


  • By default a container’s file system persists even after the container exits. This makes debugging a lot easier (since you can inspect the final state) and you retain all your data by default. But if you are running short-term foreground processes, these container file systems can really pile up. If instead you’d like Docker to automatically clean up the container and remove the file system when the container exits, you can add the --rm flag.

Push docker image to docker repository

$ docker tag perfbench:latest noname/perfbench:latest
$ docker push noname/perfbench:latest