cucker/image2df

By cucker

Updated about 1 year ago

generate dockerfile by an image.

Image
Developer Tools
6

3.1K

What is image2df

image2df is a tool for Generate Dockerfile by an image.

This tool is very useful when you only have an image and need to generate a Dockerfile with it.

How does it work

Parsing by the history information of an image.

Quick reference

Supported tags and respective Dockerfile links

Change logs
  • 1.4
    • Fix EXPOSE instruct fotmat. EXPOSE instruct format have changed in new version docker API(docker 23.0.5), such as EXPOSE map[3306/tcp:{} 53/tcp:{} ...], but Dockerfile don't support this format.
    • Fix VOLUME instruct fotmat. Such as VOLUME [/var/lib/mysql] change to VOLUME ["/var/lib/mysql"].
  • 1.3
    Fix this case, when there are more than 2 parameters on ENTRYPOINT or CMD instruction, there is no comma between the parameters.

Deficiencies

The "FROM <basc_image>" maybe is not accurate.

There is a way to get an accurate basc_image info, you should build a Library for mapping images tag to files sha256 value, a file sha256 value likes ADD file:f278386b0cef68136129f5f58c52445590a417b624d62bca158d4dc926c340df in / .

How to use this image

# Command alias
echo "alias image2df='docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock cucker/image2df'" >> ~/.bashrc
. ~/.bashrc

# Excute command
image2df <IMAGE>
  • See help

    docker run --rm cucker/image2df --help
    
    # or
    docker run --rm cucker/image2df
    
  • For example

    $ echo "alias image2df='docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock cucker/image2df'" >> ~/.bashrc
    $ . ~/.bashrc
    $ docker pull mysql
    $ image2df mysql
    
    # ========== Dockerfile ==========
    FROM mysql:latest
    ADD file:61a2085af5116916e7b117c2e7ad7116bdc0282d8fa9ce76191c4101f5e866ff in /
    CMD ["/bin/bash"]
    RUN set -eux; \
        groupadd --system --gid 999 mysql; \
        useradd --system --uid 999 --gid 999 --home-dir /var/lib/mysql --no-create-home mysql
    ENV GOSU_VERSION=1.16
    RUN set -eux; \
        arch="$(uname -m)"; \
        case "$arch" in \
            aarch64) gosuArch='arm64' ;; \
        x86_64) gosuArch='amd64' ;; \
        *) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; \
        esac; \
        curl -fL -o /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$gosuArch.asc"; \
        curl -fL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$gosuArch"; \
        export GNUPGHOME="$(mktemp -d)"; \
        gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
        gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
        rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
        chmod +x /usr/local/bin/gosu; \
        gosu --version; \
        gosu nobody true
    RUN set -eux; \
        microdnf install -y \
            bzip2 \
            gzip \
            openssl \
            xz \
            zstd \
            findutils \
        ; \
        microdnf clean all
    RUN set -eux; \
        key='859BE8D7C586F538430B19C2467B942D3A79BD29'; \
        export GNUPGHOME="$(mktemp -d)"; \
        gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
        gpg --batch --export --armor "$key" > /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql; \
        rm -rf "$GNUPGHOME"
    ENV MYSQL_MAJOR=8.0
    ENV MYSQL_VERSION=8.0.33-1.el8
    RUN set -eu; \
        . /etc/os-release; \
        { \
            echo '[mysql8.0-server-minimal]'; \
        echo 'name=MySQL 8.0 Server Minimal'; \
        echo 'enabled=1'; \
        echo "baseurl=https://repo.mysql.com/yum/mysql-8.0-community/docker/el/${VERSION_ID%%[.-]*}/\$basearch/"; \
        echo 'gpgcheck=1'; \
        echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql'; \
        echo 'module_hotfixes=true'; \
        } | tee /etc/yum.repos.d/mysql-community-minimal.repo
    RUN set -eux; \
        microdnf install -y "mysql-community-server-minimal-$MYSQL_VERSION"; \
        microdnf clean all; \
        grep -F 'socket=/var/lib/mysql/mysql.sock' /etc/my.cnf; \
        sed -i 's!^socket=.*!socket=/var/run/mysqld/mysqld.sock!' /etc/my.cnf; \
        grep -F 'socket=/var/run/mysqld/mysqld.sock' /etc/my.cnf; \
        { echo '[client]'; echo 'socket=/var/run/mysqld/mysqld.sock'; } >> /etc/my.cnf; \
        ! grep -F '!includedir' /etc/my.cnf; \
        { echo; echo '!includedir /etc/mysql/conf.d/'; } >> /etc/my.cnf; \
        mkdir -p /etc/mysql/conf.d; \
        mkdir -p /var/lib/mysql /var/run/mysqld; \
        chown mysql:mysql /var/lib/mysql /var/run/mysqld; \
        chmod 1777 /var/lib/mysql /var/run/mysqld; \
        mkdir /docker-entrypoint-initdb.d; \
        mysqld --version; \
        mysql --version
    RUN set -eu; \
        . /etc/os-release; \
        { \
            echo '[mysql-tools-community]'; \
        echo 'name=MySQL Tools Community'; \
        echo "baseurl=https://repo.mysql.com/yum/mysql-tools-community/el/${VERSION_ID%%[.-]*}/\$basearch/"; \
        echo 'enabled=1'; \
        echo 'gpgcheck=1'; \
        echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql'; \
        echo 'module_hotfixes=true'; \
        } | tee /etc/yum.repos.d/mysql-community-tools.repo
    ENV MYSQL_SHELL_VERSION=8.0.33-1.el8
    RUN set -eux; \
        microdnf install -y "mysql-shell-$MYSQL_SHELL_VERSION"; \
        microdnf clean all; \
        mysqlsh --version
    VOLUME ["/var/lib/mysql"]
    COPY file:e9c22353a1133b89c5bca24ecacd348acd094e50e5e5c45375a997c6b1f07192 in /usr/local/bin/
    RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
    ENTRYPOINT ["docker-entrypoint.sh"]
    EXPOSE 3306 33060
    CMD ["mysqld"]
    

Docker Pull Command

docker pull cucker/image2df