Hi. I don’t know why it isn’t like in dockerhub, but most entries in the public registry are built from github. A quick search reveals https://github.com/filippobosi/docker-mfi where you can find a dockerfile. As far as I know, you cannot get the used Dockerfile from the image. It’s just used to build it.
TL;DR
So if you have a docker image that was built by a dockerfile, you can recover this information (All except from the original FROM command, which is important, I’ll grant that. But you can often guess it, especially by entering the container and asking “What os are you?”). However, the maker of the image could have manual steps that you’d never know about anyways, plus they COULD just export an image, and re-import it and there would be no intermediate images at that point.
There is only one reason why the Dockerfile is not on the hub.
It wasn’t “auto built” from the git repo.
Instead, the images are pushed from the users computer after building.
Now there are a few reasons why this would happen
The user just didn’t set it up that way, that simple.
It is a base image, created from a chroot-like directory of files. There is no Dockerfile to represent this process.
Building requires special arguments/files not available in the auto build process
It doesn’t makes sense to use the auto build structure to create multiple tags.
Building the docker image required an interactive step that wasn’t/can’t be Dockerfile-ed
etc…
However, if a Dockerfile is used (as ipptyf found it was in this case), when you docker pull the image, you can recover a history of the Dockerfile commands (which are not the dockerfile itself, but close enough). However, keep in mind that manual edits to images could have been performed and committed, and would not show up with this procedure
Manual version
docker inspect filippobosi/mfi
Shows the last command in the dockerfile used under ConatinerConfig.Cmd. It also shows the parent (aac12014)
docker inspect aac12014
Shows the second last command in the dockerfile used, etc…
Bash magic
function dc_trace_cmd() {
local parent=`docker inspect -f '{{ .Parent }}' $1` 2>/dev/null
declare -i level=$2
echo ${level}: `docker inspect -f '{{ .ContainerConfig.Cmd }}' $1 2>/dev/null`
level=level+1
if [ "${parent}" != "" ]; then
echo ${level}: $parent
dc_trace_cmd $parent $level
fi
}
dc_trace_cmd filippobosi/mfi
This will not print in “Last command first” order, the list of dockerfile commands. Remember, if an intermediate image is run and commited, there is no record of what happened. This does not guarantee you can re-create a dockerfile, only shows you the cookie crumb trail left behind.
The Last step (0:) is the CMD line of the dockerfile (here)
1: is the sha of the intermediate image (parent of 0:), and that command corresponds to this
2: is where it gets interesting. Instead of apt-get clean it is the apt-get install -f mfi-beta command. Why is this different? I would guess this is because the Dockerfile up on github is out of date. Notice it is dated June 4th, 2015, while the dockerhub image is actually dated June 3rd, but pushed 2 months ago. Either I missed something, or he added that command after building the particular image that was pushed to dockerhub (which I think is more likely).
And so on…
Step 8 is where it may get confusing. That sha probably refers to the ubuntu:14.04 image, as it was back in June of 2015… The CMD command is actually the last line in the ubuntu image. Knowing this is I guess this is where my method breaks apart… Running dc_trace_cmd ubuntu:14.04 will reveal a very similar trace of commands matching 8: - 11:
$ docker history filippobosi/mfi
IMAGE CREATED CREATED BY SIZE COMMENT
d6d2fff8c7a4 3 years ago /bin/sh -c #(nop) CMD [/usr/lib/jvm/java-6-o… 0B
<missing> 3 years ago /bin/sh -c #(nop) EXPOSE 6080/tcp 6443/tcp 0B
<missing> 3 years ago /bin/sh -c apt-get install -y mfi-beta 248MB
<missing> 3 years ago /bin/sh -c apt-get update 2.84kB
<missing> 3 years ago /bin/sh -c apt-key adv --keyserver keyserver… 25.9kB
<missing> 3 years ago /bin/sh -c echo 'deb http://dl.ubnt.com/mfi/… 1.96kB
<missing> 3 years ago /bin/sh -c apt-get update 20.8MB
<missing> 3 years ago /bin/sh -c #(nop) MAINTAINER filippobosi 0B
<missing> 3 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 3 years ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$… 1.9kB
<missing> 3 years ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/poli… 195kB
<missing> 3 years ago /bin/sh -c #(nop) ADD file:b43bf069650bac07b… 188MB
I’m an absolute beginner, and probably there are far more better ways to achieve, but the trick I do that works even if for any reason you can’t start the image.
1: first I get the files inside with
docker run -it <name_of_image> ls -la
2: I dump the content of whatever file I want (i.e: Dockerfile)
docker run -it <name_of_image> cat Dockerfile