Skip to content
LanikSJ edited this page Feb 7, 2025 · 5 revisions

Usage Instructions

Docker Usage Instructions

The Python script is itself packaged as a Docker image so it can easily be executed with the Docker run command:

docker run -v /var/run/docker.sock:/var/run/docker.sock dfimage ruby:latest

The ruby:latest parameter is the image name & tag (either the truncated form or the complete image name & tag).

Since the script interacts with the Docker API in order to query the metadata for the various image layers it needs access to the Docker API socket. The -v flag shown above makes the Docker socket available inside the container running the script.

Note that the script only works against images that exist in your local image repository (the stuff you see when you type docker images). If you want to generate a Dockerfile for an image that doesn't exist in your local repo you'll first need to docker pull it.

Podman Usage Instructions

✅ This works with podman version 4.3.1 on Ubuntu 23.10 x86_64:

    sudo podman run -v /run/podman/podman.sock:/var/run/docker.sock ghcr.io/laniksj/dfimage docker.io/library/ruby:latest

❎ Running as unprivileged user didn't work:

podman run -v /run/user/$(id -ur)/podman/podman.sock:/var/run/docker.sock ghcr.io/laniksj/dfimage docker.io/library/ruby:latest

💡 Here is the error I get in case if running unpriviledge:

Traceback (most recent call last):
  File "/app/entrypoint.py", line 126, in <module>
    __main__ = MainObj()
               ^^^^^^^^^
  File "/app/entrypoint.py", line 23, in __init__
    self._get_layers_with_images()
  File "/app/entrypoint.py", line 69, in _get_layers_with_images
    self.layers_with_images[last_layer_id] = i["RepoTags"][0]
                                             ~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

Python Usage Instructions

If you want to use python virtual environment:

python3 -m venv-dfimage
source venv-dfimage/bin/activate
dfimage alpine:latest

Or even easier with pipx

pipx install dfimage

Clone this wiki locally