Search code examples
dockerdockerfileapple-m1arm64

Build existing Docker image for another architecture without the original Dockerfile


I've got an old Docker image for linux/amd64 that I need to build for linux/arm64 (to make it run on an M1 Mac).

The problem is that there is no Dockerfile. The image has been updated throughout the years using docker commit as changes have been made to it.

Is there a way of taking a new snapshot, but for another architecture (I guess not)? What options do I have otherwise?

The image in question is a custom setup of Cassandra for local development, and I'm really not sure what configuration it has, so I'd like to avoid setting it up from scratch if possible.


Solution

  • To get the information from docker history in a readable manner the following (bash) command helped me. Just put your Image and Tag after --no-trunc

    docker history --no-trunc IMAGE:TAG | tac | tr -s ' ' | cut -d " " -f 5- | sed 's,^/bin/sh -c #(nop) ,,g' | sed 's,^/bin/sh -c,RUN,g' | sed 's,
     && ,\n  & ,g' | sed 's,\s*[0-9]*[\.]*[0-9]*\s*[kMG]*B\s*$,,g' | head -n -1
    

    There is also an image as a nice tool: Reference on Docker Hub

    Basically:

    alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage"
    dfimage IMAGE:TAG